Documentation ¶
Index ¶
- Constants
- Variables
- func CheckAuthToken(app *config.AppInfo, appId, groupId, userId, token string) (RetCode int, RetMsg string)
- func GetMaxClientIndex() uint64
- func GetTotalClientCreateCount() uint64
- func InitAppInfo()
- func PushMessage(message string) (int, string)
- func ReStartMessageService()
- func RemoveClient(client *UserClient)
- func StartMessageService()
- type AppConnData
- type AppGroups
- func (app *AppGroups) GetAndInitUserGroup(appId, groupId string) *UserGroup
- func (app *AppGroups) GetAuthLongPollCount(groupIds ...string) int
- func (app *AppGroups) GetAuthWebSocketCount(groupIds ...string) int
- func (app *AppGroups) GetGroupCount() int
- func (app *AppGroups) GetLongPollCount(groupIds ...string) int
- func (app *AppGroups) GetTotalClientCount(groupIds ...string) int
- func (ag *AppGroups) GetUserGroup(groupId string) (*UserGroup, bool)
- func (ag *AppGroups) GetUserGroups() map[string]*UserGroup
- func (app *AppGroups) GetWebSocketCount(groupIds ...string) int
- func (ag *AppGroups) SendMessage(message *Message) int
- type ConnData
- type Message
- type MessageQueue
- type UserClient
- func (uc *UserClient) GetClientInfo() string
- func (uc *UserClient) GetIndex() uint64
- func (uc *UserClient) GetReferrerUrl() string
- func (uc *UserClient) GetRemoteAddr() string
- func (uc *UserClient) GetWebSocket() *dotweb.WebSocket
- func (uc *UserClient) ReadMessage() (string, error)
- func (uc *UserClient) Reset(appId, userId, groupId, from string, isAuth bool, ws *dotweb.WebSocket, ...)
- func (uc *UserClient) SendMessage(message string)
- type UserGroup
- func (ug *UserGroup) AddClient(client *UserClient)
- func (ug *UserGroup) DeleteClient(client *UserClient)
- func (ug *UserGroup) GetAuthLongPollClientCount() int
- func (ug *UserGroup) GetAuthWebSocketClientCount() int
- func (ug *UserGroup) GetGroupId() string
- func (ug *UserGroup) GetLongPollClientCount() int
- func (ug *UserGroup) GetUserClient(userId string) (*UserClient, bool)
- func (ug *UserGroup) GetWebSocketClientCount() int
- func (ug *UserGroup) SendMessage(message *Message) int
Constants ¶
const ( ConnType_WebSocket = "websocket" ConnType_LongPoll = "longpoll" )
连接类型
const ( MessageLevel_All = "0" //"all" MessageLevel_Normal = "1" //"normal" MessageLevel_Auth = "2" //"auth" 表示仅发送给经过鉴权的连接 )
消息级别
const DefaultTimeOut = 60 //second
const MaxQueueMessageCount = 10000
const OnlineGroupID = "online"
Variables ¶
var AppPool map[string]*AppGroups
应用集合
Functions ¶
func CheckAuthToken ¶
func CheckAuthToken(app *config.AppInfo, appId, groupId, userId, token string) (RetCode int, RetMsg string)
检查应用鉴权结果 Author: panxinming CreateTime: 2017-02-07 13:00 入参: app:应用配置信息 appId:应用编号 groupid:用户组编号,应用自定义 userid:用户编号,应用需保证userid在同Appid下的唯一性 token:鉴权token 返回值: 0 成功 -101001:no permission connect! => appid[" + appId + "] no exists -101002:no permission connect! => check token has an error => [http-request-error] -101003:no permission connect! => check token has an error => [json-parse-error] -101004:no permission connect! => check token result => -101005:no permission connect! => check token: appid|groupid|userid not match
update log: 1、初始版本 --2017-02-07 13:00 by pxm
func GetMaxClientIndex ¶
func GetMaxClientIndex() uint64
func GetTotalClientCreateCount ¶
func GetTotalClientCreateCount() uint64
func PushMessage ¶
push new message result: -10001:jsonunmar error -10002:this appid no have permission
Types ¶
type AppConnData ¶
type AppGroups ¶
type AppGroups struct {
// contains filtered or unexported fields
}
表示用户组的集合
func (*AppGroups) GetAndInitUserGroup ¶
get and init UserGroup with appid
func (*AppGroups) GetAuthLongPollCount ¶
get app's auth longpoll client count
func (*AppGroups) GetAuthWebSocketCount ¶
get app's auth websocke client count
func (*AppGroups) GetGroupCount ¶
get app's usergroup count
func (*AppGroups) GetLongPollCount ¶
get app's longpoll client count
func (*AppGroups) GetTotalClientCount ¶
get app's total client count
func (*AppGroups) GetUserGroup ¶
获取指定用户组
func (*AppGroups) GetUserGroups ¶
获取用户组列表
func (*AppGroups) GetWebSocketCount ¶
get app's websocke client count
func (*AppGroups) SendMessage ¶
send a meeage for full app groups return send client count
type ConnData ¶
type ConnData struct { Apps []AppConnData DataTime time.Time }
type Message ¶
type Message struct { //消息关联AppID AppID string //消息关联GroupID GroupID string //消息关联UserID UserID string //消息接收级别 - 目前分为all、auth、normal -匹配MessageLevel_Const MessageLevel string //消息接收AppID ToAppID string //消息接收GroupID ToGroupID string //消息接收UserID ToUserID string //消息内容 Content string }
消息定义
type UserClient ¶
type UserClient struct { Index uint64 //客户端唯一索引 ConnType string MessageChan chan string `json:"-"` TimeOut int64 //超时时间 - 单位为秒 From string //请求来源,比如site、mobile、jrpt等 UserID string //user id GroupId string //用户组编号 AppId string //用户应用编号 RemoteIP string //用户IP信息“ip:port” ReferrerUrl string //ReferrerUrl IsAuth bool //是否带鉴权 // contains filtered or unexported fields }
user client for websocket
func NewClient ¶
func NewClient(appId, userId, groupId, from string, isAuth bool, ws *dotweb.WebSocket, context dotweb.Context) *UserClient
create a new UserClient with socketconn&userinfo
func (*UserClient) GetClientInfo ¶
func (uc *UserClient) GetClientInfo() string
get client's json string
func (*UserClient) GetReferrerUrl ¶
func (uc *UserClient) GetReferrerUrl() string
get client's referrer url
func (*UserClient) GetRemoteAddr ¶
func (uc *UserClient) GetRemoteAddr() string
get client's remoteaddr
func (*UserClient) GetWebSocket ¶
func (uc *UserClient) GetWebSocket() *dotweb.WebSocket
get client's websocket
func (*UserClient) ReadMessage ¶
func (uc *UserClient) ReadMessage() (string, error)
read message from websocket.conn or hijackConn
func (*UserClient) Reset ¶
func (uc *UserClient) Reset(appId, userId, groupId, from string, isAuth bool, ws *dotweb.WebSocket, context dotweb.Context)
reset userclient attr
func (*UserClient) SendMessage ¶
func (uc *UserClient) SendMessage(message string)
send message to client
type UserGroup ¶
type UserGroup struct {
// contains filtered or unexported fields
}
表示一组用户
func GetUserGroup ¶
get usergroup with appid & groupid
func RegisterClient ¶
func RegisterClient(client *UserClient) (*UserGroup, int)
register new userclient with roomid return values: -10001: not exists appid -10002: usergroup error 0: ok
func (*UserGroup) AddClient ¶
func (ug *UserGroup) AddClient(client *UserClient)
add new client into usergroup
func (*UserGroup) DeleteClient ¶
func (ug *UserGroup) DeleteClient(client *UserClient)
delete a userclient
func (*UserGroup) GetAuthLongPollClientCount ¶
get usergroup's auth longpollclient count
func (*UserGroup) GetAuthWebSocketClientCount ¶
get usergroup's auth websocketclient count
func (*UserGroup) GetGroupId ¶
func (*UserGroup) GetLongPollClientCount ¶
get usergroup's longpollclient count
func (*UserGroup) GetUserClient ¶
func (ug *UserGroup) GetUserClient(userId string) (*UserClient, bool)
获取指定UserId的用户客户端代理
func (*UserGroup) GetWebSocketClientCount ¶
get usergroup's websocketclient count
func (*UserGroup) SendMessage ¶
send a meeage for full group return send client count