The private message module for golang project. (IMPORTANT: The API and data structure may change!)
It is using PostgreSQL as the database and will create a table:
CREATE TABLE IF NOT EXISTS private_msg (
id uuid primary key,
from_userid integer,
to_userid integer,
message text,
read boolean,
at integer
);
CREATE INDEX IF NOT EXISTS index_private_msg_to_userid ON private_msg (to_userid);
CREATE INDEX IF NOT EXISTS index_private_msg_from_userid ON private_msg (from_userid);
CREATE INDEX IF NOT EXISTS index_private_msg_at ON private_msg (at);
go get github.com/jackc/pgx
go get github.com/satori/go.uuid
First need to use the module with the pgx pool passed in:
err := kkpm.Use(pool)
Get the unread messages count:
count, err := GetUnreadCount(2);
Mark all messages from the user id as read:
err := ReadFrom(2, 3);
Get the messages sent:
result, err := kkpm.GetSentMessages(3, 0);
The second parameter is unixtime, the messages sent later than that will be got.
Get the messages received:
result, err := kkpm.GetReveivedMessages(3, 0);
The second parameter is unixtime, the messages received later than that will be got.
Get the messages between two people:
result, err := kkpm.GetPeerChat(3, 2, 0);
The third parameter is unixtime, the messages later than that will be got.