Documentation ¶
Index ¶
- Constants
- Variables
- func AddChatRoomRobot(req *session.UserChatRoomRequest) error
- func AddChatRoomUser(req *session.UserChatRoomRequest) (int, error)
- func AddChatroomCountKeys(appid uint16, roomids []string) error
- func AddQpsCount(module, api string, limit int) (bool, error)
- func CacheChatRoomMessage(req *logic.ChatRoomMessage) (uint, error)
- func CheckUserSessionInRoom(req *session.UserChatRoomRequest) (bool, error)
- func CleanChatRoom(room string, appid uint16) error
- func CreateChatRoom(req *session.UserChatRoomRequest) error
- func DelChatroomCountKeys(appid uint16, roomids []string) error
- func GetActiveChatRoomNum(appid uint16) (int, error)
- func GetActiveUserNum(appid uint16) (int, error)
- func GetActiveUserSessions(appid uint16, zoneid uint16) ([]*session.UserSession, error)
- func GetCachedChatRoomMessages(req *FetchChatRoomMessageReq) (map[uint]*logic.ChatRoomMessage, error)
- func QueryChatRoomDetail(room string, appid uint16) (*session.ChatRoomDetail, error)
- func QueryChatRoomMemberCount(rooms []string, appid uint16) (map[string]map[string]int, error)
- func QueryChatRoomUsers(room string, appid uint16) ([]string, error)
- func QueryChatRoomsByZone(appid uint16, zoneid uint16) (map[string]*session.ChatRoomDetail, error)
- func QueryUserInRoom(room string, user string, appid uint16) (bool, error)
- func QueryUserSession(query []*session.UserSession) ([]*session.UserSession, error)
- func QueryUserSessionChatRoomList(req *session.UserChatRoomRequest) ([]string, error)
- func QueryUserSessionSummary(appid uint16, user string) (map[string]int, error)
- func RemoveChatRoomRobot(req *session.UserChatRoomRequest) error
- func RemoveChatRoomUser(req *session.UserChatRoomRequest) (int, error)
- func RemoveSession(userSession *session.UserSession) error
- func SaveSession(userSession *session.UserSession) ([]*session.UserSession, error)
- func SetMethodNetOptinons(service string, netOptionsList map[string]*gorpc.NetOptions) error
- func UpdateChatRoomMember(req *ChatRoomMemberUpdate) error
- type ChatMessage
- type ChatRoomMemberUpdate
- type ChatRoomsAppid
- type ChatroomCountKeysRequest
- type ChatroomCountKeysResponse
- type FetchChatRoomMessageReq
- type GetActiveReq
- type GetChatroomCountKeysRequest
- type GroupAppid
- type GroupMsgReq
- type QpsCount
- type RecallMessagesRequest
- type RetrieveChannel
- type RetrieveMessagesRequest
- type RetrieveMessagesResponse
- type SaverStat
- func (stat *SaverStat) Add(add *SaverStat) *SaverStat
- func (stat *SaverStat) AtomicAddCloseSessionFails(i uint64) uint64
- func (stat *SaverStat) AtomicAddCloseSessions(i uint64) uint64
- func (stat *SaverStat) AtomicAddOpenSessionFails(i uint64) uint64
- func (stat *SaverStat) AtomicAddOpenSessions(i uint64) uint64
- func (stat *SaverStat) AtomicAddP2pResponseTime(i uint64) uint64
- func (stat *SaverStat) AtomicAddQuerySessionFails(i uint64) uint64
- func (stat *SaverStat) AtomicAddQuerySessionSuccess(i uint64) uint64
- func (stat *SaverStat) AtomicAddQuerySessions(i uint64) uint64
- func (stat *SaverStat) AtomicAddRetrieveImFails(i uint64) uint64
- func (stat *SaverStat) AtomicAddRetrieveIms(i uint64) uint64
- func (stat *SaverStat) AtomicAddRetrievePeerFails(i uint64) uint64
- func (stat *SaverStat) AtomicAddRetrievePeers(i uint64) uint64
- func (stat *SaverStat) AtomicAddRetrievePublicResponseTime(i uint64) uint64
- func (stat *SaverStat) AtomicAddRetrievePublics(i uint64) uint64
- func (stat *SaverStat) AtomicAddSessionResponseTime(i uint64) uint64
- func (stat *SaverStat) AtomicAddStoreIMFails(i uint64) uint64
- func (stat *SaverStat) AtomicAddStoreIMs(i uint64) uint64
- func (stat *SaverStat) AtomicAddStorePeerFails(i uint64) uint64
- func (stat *SaverStat) AtomicAddStorePeers(i uint64) uint64
- func (stat *SaverStat) AtomicCopyTo(copy *SaverStat) *SaverStat
- func (stat *SaverStat) AtomicGetCloseSessionFails() uint64
- func (stat *SaverStat) AtomicGetCloseSessions() uint64
- func (stat *SaverStat) AtomicGetOpenSessionFails() uint64
- func (stat *SaverStat) AtomicGetOpenSessions() uint64
- func (stat *SaverStat) AtomicGetQuerySessionFails() uint64
- func (stat *SaverStat) AtomicGetQuerySessionSuccess() uint64
- func (stat *SaverStat) AtomicGetQuerySessions() uint64
- func (stat *SaverStat) AtomicGetRetrieveImFails() uint64
- func (stat *SaverStat) AtomicGetRetrieveIms() uint64
- func (stat *SaverStat) AtomicGetRetrievePeerFails() uint64
- func (stat *SaverStat) AtomicGetRetrievePeers() uint64
- func (stat *SaverStat) AtomicGetRetrievePublicResponseTime() uint64
- func (stat *SaverStat) AtomicGetRetrievePublics() uint64
- func (stat *SaverStat) AtomicGetStatResponse() bool
- func (stat *SaverStat) AtomicGetStoreIMFails() uint64
- func (stat *SaverStat) AtomicGetStoreIMs() uint64
- func (stat *SaverStat) AtomicGetStorePeerFails() uint64
- func (stat *SaverStat) AtomicGetStorePeers() uint64
- func (stat *SaverStat) AtomicGetTotalP2pResponseTime() uint64
- func (stat *SaverStat) AtomicGetTotalSessionResponseTime() uint64
- func (stat *SaverStat) AtomicMakeQps(i uint64) string
- func (stat *SaverStat) AtomicSetStatResponse(value bool)
- func (stat *SaverStat) AtomicTotalIMRequests() uint64
- func (stat *SaverStat) AtomicTotalP2PMsgRequests() uint64
- func (stat *SaverStat) AtomicTotalPeerRequests() uint64
- func (stat *SaverStat) AtomicTotalSessionRequests() uint64
- func (stat *SaverStat) QpsString() string
- func (stat *SaverStat) String() string
- func (stat *SaverStat) Sub(sub *SaverStat) *SaverStat
- type StoreMessagesRequest
- type StoreMessagesResponse
- type UserAppid
- type UserChatRoom
Constants ¶
const ( GroupJoined = "join" GroupCreated = "owner" GroupAll = "all" )
const ( ReqRoleGroupExited = 1 ReqRoleGroupUser = 2 ReqRoleGroupOwner = 4 ReqRoleGroupUserOrOwner = 6 ReqRoleGroupAll = 255 )
const ( ChatChannelNotify = "peer" ChatChannelPublic = "public" ChatChannelIM = "im" ChatChannelIMInbox = "iminbox" ChatChannelIMOutbox = "imoutbox" )
Variables ¶
var ( ErrNotFound = errors.New("specified message not found") ErrRecalledYet = errors.New("message has been recalled yet") )
var GorpcClient *gorpc.Client = func() *gorpc.Client { netOptions := gorpc.NewNetOptions(gorpc.DefaultConnectTimeout, gorpc.DefaultReadTimeout, gorpc.DefaultWriteTimeout) g := gorpc.NewClient(netOptions) statNetOption := gorpc.NewNetOptions(1*time.Second, 1*time.Second, 1*time.Second) g.SetMethodNetOptinons("GorpcService", "GetSaverQps", statNetOption) g.SetMethodNetOptinons("GorpcService", "GetSaverTotalOps", statNetOption) return g }()
Functions ¶
func AddChatRoomRobot ¶
func AddChatRoomRobot(req *session.UserChatRoomRequest) error
func AddChatRoomUser ¶
func AddChatRoomUser(req *session.UserChatRoomRequest) (int, error)
func AddChatroomCountKeys ¶
func CacheChatRoomMessage ¶
func CacheChatRoomMessage(req *logic.ChatRoomMessage) (uint, error)
func CheckUserSessionInRoom ¶
func CheckUserSessionInRoom(req *session.UserChatRoomRequest) (bool, error)
func CleanChatRoom ¶
func CreateChatRoom ¶
func CreateChatRoom(req *session.UserChatRoomRequest) error
func DelChatroomCountKeys ¶
func GetActiveChatRoomNum ¶
func GetActiveUserNum ¶
func GetActiveUserSessions ¶
func GetActiveUserSessions(appid uint16, zoneid uint16) ([]*session.UserSession, error)
func GetCachedChatRoomMessages ¶
func GetCachedChatRoomMessages(req *FetchChatRoomMessageReq) (map[uint]*logic.ChatRoomMessage, error)
func QueryChatRoomDetail ¶
func QueryChatRoomDetail(room string, appid uint16) (*session.ChatRoomDetail, error)
func QueryChatRoomsByZone ¶
func QueryUserInRoom ¶
判断用户是否在某直播间
func QueryUserSession ¶
func QueryUserSession(query []*session.UserSession) ([]*session.UserSession, error)
func QueryUserSessionChatRoomList ¶
func QueryUserSessionChatRoomList(req *session.UserChatRoomRequest) ([]string, error)
func QueryUserSessionSummary ¶
func RemoveChatRoomRobot ¶
func RemoveChatRoomRobot(req *session.UserChatRoomRequest) error
func RemoveChatRoomUser ¶
func RemoveChatRoomUser(req *session.UserChatRoomRequest) (int, error)
func RemoveSession ¶
func RemoveSession(userSession *session.UserSession) error
func SaveSession ¶
func SaveSession(userSession *session.UserSession) ([]*session.UserSession, error)
func SetMethodNetOptinons ¶
func SetMethodNetOptinons(service string, netOptionsList map[string]*gorpc.NetOptions) error
func UpdateChatRoomMember ¶
func UpdateChatRoomMember(req *ChatRoomMemberUpdate) error
Types ¶
type ChatMessage ¶
type ChatMessage struct { Content string // content of the message Type uint32 // message type, like text, voice, picture or others To string // message recipient From string // message initiator TraceSN int64 // the unique message sequence number used to trace message ExpireInterval int // expire time interval, the unit is second StoreOutbox uint8 // indicate the message box to store, 0 for inbox only, 1 for both inbox and outbox. // below fields usually are generated by saver MsgId uint64 // unique message id Creation time.Time // the time when the message is saved ExpireTime time.Time // the time when the message is expired, it means saver will remove this message from DB after that point Box uint8 // indicate the message is retrieved from which message box, 0 is from inbox, 1 is from outbox. }
* Message struct, is used to store/retrieve the messages from saver * * Caller filled fields: * Content: the message's content * Type: the message content's type * To: the key info, such as jid, of message recipient * From: the key info, such as jid, of message sender * TraceSN: the unique message sequence number * ExpireInterval: indicates that message will be deleted after expire time interval from saved time, * the unit is second. The value range of this filed is min ~ max expire time interval seconds which * defined in config; saver will treat all data less than min as min while treat all * data more than max as max. * If this field is not set, the default is used. * By default, the default is 604,800s (7 days), min is 3600s (1 hours) * while max is 8,640,000s (100 days). * Also we allow to define independent expire time interval for special message types in config * * StoreOutbox: indicate the message retrieved from which message box, 0 is from inbox, 1 is from outbox. * This field is used by 'im' channel messages only and will not be stored * * Below fields usually are generated by saver * MsgId: unique message id if message saved successfully * Creation: the time when the message is saved in storage * ExpireTime: the time when the message is expired, it means saver will remove this message from storage after that point * Box: indicates the message is retrieved from which message box, 0 is from inbox, 1 is from outbox.
func (*ChatMessage) JsonString ¶
func (msg *ChatMessage) JsonString() string
func (*ChatMessage) String ¶
func (msg *ChatMessage) String() string
* default string will not include content information
func (*ChatMessage) ToString ¶
func (msg *ChatMessage) ToString(args ...string) string
type ChatRoomMemberUpdate ¶
type ChatRoomsAppid ¶
type ChatroomCountKeysResponse ¶
type ChatroomCountKeysResponse struct {
Roomids []string
}
func GetChatroomCountKeys ¶
func GetChatroomCountKeys(appid uint16, rpcIndex, rpcLength int, clientIP string) (*ChatroomCountKeysResponse, error)
type FetchChatRoomMessageReq ¶
type GetActiveReq ¶
type GroupAppid ¶
type GroupMsgReq ¶
type RecallMessagesRequest ¶
type RecallMessagesRequest struct { Appid uint16 ChatChannel string Sender string Receiver string InboxId uint64 TraceSN string }
* [Request] other modules -> saver; this is used by recall notification/im messages functions * Appid: application id * ChatChannel: indicates information of channels will be recalled * Sender: the sender of message which need to be recalled * Receiver: the receiver of message which need to be recalled * InboxId: the msg id from inbox to indicate which one should be delete
func (RecallMessagesRequest) String ¶
func (req RecallMessagesRequest) String() string
type RetrieveChannel ¶
* RetrieveChannel indicates message of what channel will be retrieved * Channel: tells the channel type of the message to be retrieved, so far only 'notify', 'public', 'im', 'imInbox' and * 'imOutbox' are supported. * If this field is filled and value isn't 'notify', 'public', 'im', 'imInbox' and 'imOutbox' or not filled, * this entry will be ignored when saver is handling retrieve message request. * 'notify' type: request to retrieve notification channel messages * 'public' type: request to retrieve public channel messages * 'im' type: request to retrieve im channel messages, both inbox and outbox * 'imInbox' type: request to retrieve im channel messages, inbox only * 'imOutBox' type: request to retrieve im channel messages, outbox only * StartMsgId: inclusive message id base; * set as 0 will return messages from last read include last read, * set as negative will return latest messages * otherwise will return from request start id if there are * MaxCount: max return count in this request; this field is set as 0 will use default value 5 * this field is set as negative will return messages before start id
func (RetrieveChannel) String ¶
func (info RetrieveChannel) String() string
type RetrieveMessagesRequest ¶
type RetrieveMessagesRequest struct { Appid uint16 Owner string ChatChannels map[string]*RetrieveChannel TraceSN string }
* [Request] other modules -> saver; this is used by retrieve notification/im/public messages functions * Appid: application id * Owner: owner who requests to retrieve messages * ChatChannels: indicates information of channels will be retrieved
func (RetrieveMessagesRequest) String ¶
func (req RetrieveMessagesRequest) String() string
type RetrieveMessagesResponse ¶
type RetrieveMessagesResponse struct { Inbox map[string][]*ChatMessage Outbox map[string][]*ChatMessage LatestID map[string]uint64 LastReadID map[string]uint64 Appid uint16 Owner string }
* [Response] saver -> other modules; this is used by retrieve notification/im/public messages response * * Inbox: messages have been retrieved from inbox storage; key is channels in request and value are message slice of * channel. If a channel in request is not found in Inbox means there isn't any messages from specified start id * have response in this field * Outbox: messages have been retrieved from inbox storage; key is channels in request and value are message slice of * channel. So far only IM channel may have outbox * LatestID: each latest ID of channels in request * LastReadID: each last read ID of channels in request
func RetrieveChatMessages ¶
func RetrieveChatMessages(req *RetrieveMessagesRequest) (*RetrieveMessagesResponse, error)
* Retrieves chat messages from storage * @param req is a saver.RetrieveMessagesRequest point which include retrieving request information * @param resp is a saver.RetrieveMessagesResponse point which includes response * @return (*RetrieveMessagesResponse, nil) if no error occurs, otherwise (nil, error) is returned
func RetrieveUnreadCount ¶
func RetrieveUnreadCount(appid uint16, userIds, channels []string) ([]*RetrieveMessagesResponse, error)
获取未读消息数
func (RetrieveMessagesResponse) String ¶
func (resp RetrieveMessagesResponse) String() string
type SaverStat ¶
type SaverStat struct { OpenSessions uint64 OpenSessionFails uint64 CloseSessions uint64 CloseSessionFails uint64 QuerySessions uint64 QuerySessionSuccess uint64 QuerySessionFails uint64 TotalSessionResponseTime uint64 StoreIMs uint64 StoreIMFails uint64 RetrieveIms uint64 RetrieveImFails uint64 StorePeers uint64 StorePeerFails uint64 RetrievePeers uint64 RetrievePeerFails uint64 TotalP2pResponseTime uint64 RetrievePublics uint64 RetrievePublicResponseTime uint64 StatResponse int32 }
func GetSaverQps ¶
* get saver qps from specified saver * @param saverGorpcAddr is specified saver go rpc address * @return (*SaverStat, nil) if successful, otherwise (*SaverStat{}, error) will be return
func GetSaverTotalOps ¶
* get saver total operations count after start from specified saver * @param saverGorpcAddr is specified saver go rpc address * @return (*SaverStat, nil) if successful, otherwise (*SaverStat{}, error) will be return
func (*SaverStat) Add ¶
* stat add add and then store result in stat * @param add is value will be added * @return stat with new value
func (*SaverStat) AtomicAddCloseSessionFails ¶
func (*SaverStat) AtomicAddCloseSessions ¶
func (*SaverStat) AtomicAddOpenSessionFails ¶
func (*SaverStat) AtomicAddOpenSessions ¶
func (*SaverStat) AtomicAddP2pResponseTime ¶
* add a p2p message request response time to total atomicly * @param i is p2p message request response time with unit nanosecond * @return new total p2p message request response time
func (*SaverStat) AtomicAddQuerySessionFails ¶
func (*SaverStat) AtomicAddQuerySessionSuccess ¶
func (*SaverStat) AtomicAddQuerySessions ¶
func (*SaverStat) AtomicAddRetrieveImFails ¶
func (*SaverStat) AtomicAddRetrieveIms ¶
func (*SaverStat) AtomicAddRetrievePeerFails ¶
func (*SaverStat) AtomicAddRetrievePeers ¶
func (*SaverStat) AtomicAddRetrievePublicResponseTime ¶
func (*SaverStat) AtomicAddRetrievePublics ¶
func (*SaverStat) AtomicAddSessionResponseTime ¶
* add a session request response time to total atomicly * @param i is session request response time with unit nanosecond * @return new total session request response time
func (*SaverStat) AtomicAddStoreIMFails ¶
func (*SaverStat) AtomicAddStoreIMs ¶
func (*SaverStat) AtomicAddStorePeerFails ¶
func (*SaverStat) AtomicAddStorePeers ¶
func (*SaverStat) AtomicCopyTo ¶
* this copy content of stat to 'copy' atomicly * @param copy is target the content copy to * @return copy if it is not nil, otherwise will return a new SaverStat point
func (*SaverStat) AtomicGetCloseSessionFails ¶
func (*SaverStat) AtomicGetCloseSessions ¶
func (*SaverStat) AtomicGetOpenSessionFails ¶
func (*SaverStat) AtomicGetOpenSessions ¶
* get total open session request count atomicly
func (*SaverStat) AtomicGetQuerySessionFails ¶
func (*SaverStat) AtomicGetQuerySessionSuccess ¶
func (*SaverStat) AtomicGetQuerySessions ¶
func (*SaverStat) AtomicGetRetrieveImFails ¶
func (*SaverStat) AtomicGetRetrieveIms ¶
func (*SaverStat) AtomicGetRetrievePeerFails ¶
func (*SaverStat) AtomicGetRetrievePeers ¶
func (*SaverStat) AtomicGetRetrievePublicResponseTime ¶
func (*SaverStat) AtomicGetRetrievePublics ¶
func (*SaverStat) AtomicGetStatResponse ¶
func (*SaverStat) AtomicGetStoreIMFails ¶
func (*SaverStat) AtomicGetStoreIMs ¶
func (*SaverStat) AtomicGetStorePeerFails ¶
func (*SaverStat) AtomicGetStorePeers ¶
func (*SaverStat) AtomicGetTotalP2pResponseTime ¶
func (*SaverStat) AtomicGetTotalSessionResponseTime ¶
func (*SaverStat) AtomicMakeQps ¶
* this computes qps with stat according to interval * @param i is interval which unit is second * @return a json string that include saver QPS information
func (*SaverStat) AtomicSetStatResponse ¶
func (*SaverStat) AtomicTotalIMRequests ¶
* get total IM request count atomicly
func (*SaverStat) AtomicTotalP2PMsgRequests ¶
* get total p2p message request count atomicly
func (*SaverStat) AtomicTotalPeerRequests ¶
* get total peer request count atomicly
func (*SaverStat) AtomicTotalSessionRequests ¶
* get total session request count atomicly
type StoreMessagesRequest ¶
type StoreMessagesRequest struct { Appid uint16 Messages map[string]*ChatMessage ChatChannel string TraceSN string }
* [Request] other modules -> saver; this is used by store notification/im/public messages functions * Appid: application id * Messages: messages need to store; key is receiver of stored messages * ChatChannel: tells the channel type of the message to store, so far only 'notify', 'im' and 'public' * are supported. If this field isn't filled, saver treats it as 'notify' type. * If this field is filled and value isn't 'notify', 'im' and 'public', * a error code will be returned. * 'notify' type: requires all caller filled fields in Message. And 'To' and 'From' fields cannot be * empty string, otherwise the message will be discarded directly with no correspond message in response. * This type message supports to set its own expire time during in range 1~604800 seconds * The default expire time is 604800 seconds if ExpireInterval field isn't filled * 'public' type: requires that ExpireInterval field of messages is filled, otherwise the message * will be discarded directly. This type message does not require 'to' and 'from' fields * 'im' type: IM message, likes 'notify' message but it allows messages are store to outbox too if need
func (StoreMessagesRequest) String ¶
func (req StoreMessagesRequest) String() string
type StoreMessagesResponse ¶
type StoreMessagesResponse struct { Inbox map[string]*ChatMessage Outbox map[string]*ChatMessage }
* [Response] saver -> other modules; this is used by store notification/im/public messages response * Note that store functions will not return error if any message is discarded for invalid value; * if a message cannot be found in response by its TraceSN, it is discarded for invalid value * * Inbox: messages have been stored to inbox of receiver; key is receiver of stored messages * Outbox: messages have been stored to outbox of sender; key is receiver of stored messages * Note: the count of Messages might not be equal to request.Messages for they might be discarded for invalid value
func RecallChatMessages ¶
func RecallChatMessages(req *RecallMessagesRequest) (*StoreMessagesResponse, error)
* Set chat messages recall flag to storage * @param req is a saver.RecallMessagesRequest point which include recall request information * @param resp is a saver.StoreMessagesResponse point which includes response * @return (*StoreMessagesResponse, nil) if no error occurs, otherwise (nil, error) is returned
func StoreChatMessages ¶
func StoreChatMessages(req *StoreMessagesRequest) (*StoreMessagesResponse, error)
* Stores chat messages to storage * @param req is a saver.StoreMessagesRequest point which include messages information need to store * @return (*StoreMessagesResponse, nil) if no error occurs, otherwise (nil, error) is returned
func (StoreMessagesResponse) String ¶
func (resp StoreMessagesResponse) String() string