Documentation
¶
Index ¶
- Constants
- Variables
- func ConsumerNumGoroutine() (int64, int64)
- func Handle(cc CallbackCommand, up *URLParams, body []byte) interface{}
- func HandleEvents(event *CallbackEvent) interface{}
- func HandleEventsHttp(w http.ResponseWriter, r *http.Request)
- func RegisterBeforeHook(defaultHandle func(*CallbackEvent) interface{})
- func RegisterDefaultCallbackHandler(masterNum, msgEventLen int, defaultHandle func(*CallbackEvent) interface{}) (err error)
- func RegisterDefaultHandle(defaultHandle func(*CallbackEvent) interface{})
- func RegisterDefaultNewCallbackHandlerWithCache(masterNum, msgEventLen int, defaultHandle func(*CallbackEvent) interface{}, ...) (err error)
- func RegisterRouterInfo(cc CallbackCommand, ri RouterInfo)
- type ActionStatus
- type BaseBody
- type BaseResponse
- type CallbackCommand
- type CallbackEvent
- type CallbackHandle
- type CallbackHandler
- func (ch *CallbackHandler) ConsumerNumGoroutine() (master, assistActive int64)
- func (ch *CallbackHandler) Exist(cc CallbackCommand) bool
- func (ch *CallbackHandler) Get(cc CallbackCommand) (RouterInfo, bool)
- func (ch *CallbackHandler) Handle(ce *CallbackEvent) interface{}
- func (ch *CallbackHandler) InitProducerConsumer(masterNum, msgEventLen int, pcType string, cache producerConsumer.ICache) error
- func (ch *CallbackHandler) NewCallbackEvent(cc CallbackCommand, up *URLParams, body []byte) *CallbackEvent
- func (ch *CallbackHandler) Register(cc CallbackCommand, ri RouterInfo) *CallbackHandler
- func (ch *CallbackHandler) RegisterBeforeHook(beforeHook CallbackHandle) *CallbackHandler
- func (ch *CallbackHandler) RegisterDefaultHandle(callbackHandle CallbackHandle) *CallbackHandler
- func (ch *CallbackHandler) UnRegister(cc CallbackCommand) *CallbackHandler
- type GroupInfo
- type GroupSendMsgBody
- type GroupType
- type ICache
- type OptPlatform
- type RouterInfo
- type SendMsgBody
- type URLParams
Constants ¶
View Source
const ( //-- 单发消息 -- CallbackBeforeSendMsgCommand = CallbackCommand("C2C.CallbackBeforeSendMsg") // 发消息之前回调 CallbackAfterSendMsgCommand = CallbackCommand("C2C.CallbackAfterSendMsg") // 发消息之后回调 //-- 群组系统 -- CallbackBeforeCreateGroupCommand = CallbackCommand("Group.CallbackBeforeCreateGroup") // 创建群组之前回调 CallbackAfterCreateGroupCommand = CallbackCommand("Group.CallbackAfterCreateGroup") // 创建群组之后回调 CallbackBeforeApplyJoinGroupCommand = CallbackCommand("Group.CallbackBeforeApplyJoinGroup") // 申请入群之前回调 CallbackBeforeInviteJoinGroupCommand = CallbackCommand("Group.CallbackBeforeInviteJoinGroup") // 拉人入群之后回调 CallbackAfterNewMemberJoinCommand = CallbackCommand("Group.CallbackAfterNewMemberJoin") // 新成员入群之后回调 CallbackAfterMemberExitCommand = CallbackCommand("Group.CallbackAfterMemberExit") // 群成员离开之后回调 GroupCallbackBeforeSendMsgCommand = CallbackCommand("Group.CallbackBeforeSendMsg") // 群内发言之前回调 GroupCallbackAfterSendMsgCommand = CallbackCommand("Group.CallbackAfterSendMsg") // 群内发言之后回调 CallbackAfterGroupFullCommand = CallbackCommand("Group.CallbackAfterGroupFull") // 群组满员之后回调 CallbackAfterGroupDestroyedCommand = CallbackCommand("Group.CallbackAfterGroupDestroyed") // 群组解散之后回调 CallbackAfterGroupInfoChangedCommand = CallbackCommand("Group.CallbackAfterGroupInfoChanged") // 群组资料修改之后回调 //-- 关系链系统 -- CallbackFriendAddCommand = CallbackCommand("Sns.CallbackFriendAdd") // 添加好友之后回调 CallbackFriendDeleteCommand = CallbackCommand("Sns.CallbackFriendDelete") // 删除好友之后回调 CallbackBlackListAddCommand = CallbackCommand("Sns.CallbackBlackListAdd") // 添加黑名单之后回调 CallbackBlackListDeleteCommand = CallbackCommand("Sns.CallbackBlackListDelete") // 删除黑名单之后回调 //-- 在线状态 -- StateChangeCommand = CallbackCommand("State.StateChange") // 状态变更回调 // 客户端平台 RestAPIPlatform = OptPlatform("RESTAPI") WebPlatform = OptPlatform("Web") AndroidPlatform = OptPlatform("Android") IOSPlatform = OptPlatform("iOS") WindowsPlatform = OptPlatform("Windows") MacPlatform = OptPlatform("Mac") UnkownPlatform = OptPlatform("Unkown") // 请求处理结果 OkStatus = ActionStatus("OK") FAILStatus = ActionStatus("FAIL") // 群组系统当前提供四种默认群组形态 PrivateGroupType = GroupType("Private") PublicGroupType = GroupType("Public") ChatRoomGroupType = GroupType("ChatRoom") AVChatRoomGroupType = GroupType("AVChatRoom") )
Variables ¶
View Source
var (
BodyMaxLen int64 = 2048 //请求body实体内容限制长度值
)
View Source
var (
Version = "0.1"
)
Functions ¶
func ConsumerNumGoroutine ¶
func Handle ¶
func Handle(cc CallbackCommand, up *URLParams, body []byte) interface{}
func HandleEvents ¶
func HandleEvents(event *CallbackEvent) interface{}
func HandleEventsHttp ¶
func HandleEventsHttp(w http.ResponseWriter, r *http.Request)
原始http请求处理
对于body内容目前做长度限制,具体查看变量BodyMaxLen
func RegisterBeforeHook ¶
func RegisterBeforeHook(defaultHandle func(*CallbackEvent) interface{})
func RegisterDefaultCallbackHandler ¶
func RegisterDefaultCallbackHandler(masterNum, msgEventLen int, defaultHandle func(*CallbackEvent) interface{}) (err error)
func RegisterDefaultHandle ¶
func RegisterDefaultHandle(defaultHandle func(*CallbackEvent) interface{})
func RegisterDefaultNewCallbackHandlerWithCache ¶
func RegisterDefaultNewCallbackHandlerWithCache(masterNum, msgEventLen int, defaultHandle func(*CallbackEvent) interface{}, cache ICache) (err error)
func RegisterRouterInfo ¶
func RegisterRouterInfo(cc CallbackCommand, ri RouterInfo)
Types ¶
type BaseResponse ¶
type BaseResponse struct {
// 请求处理的结果,
// OK表示处理成功,FAIL表示失败。
ActionStatus ActionStatus
// 错误码
ErrorCode int
//错误信息。
ErrorInfo string
}
基本应答包字段
type CallbackCommand ¶
type CallbackCommand string
回调命令 @link https://www.qcloud.com/doc/product/269/1523
type CallbackEvent ¶
type CallbackEvent struct {
// 事件标识命令
CallbackCommand CallbackCommand `json:"CallbackCommand"`
// 参数
URLParams *URLParams `json:"URLParams"`
// 实体内容
Body []byte `json:"Body"`
// 句柄
Handler *CallbackHandler
}
事件实体
func CreateEvents ¶
func CreateEvents(cc CallbackCommand, up *URLParams, body []byte) *CallbackEvent
func NewCallbackEvent ¶
func NewCallbackEvent(cc CallbackCommand, up *URLParams, body []byte) *CallbackEvent
新建
func (*CallbackEvent) Handle ¶
func (ce *CallbackEvent) Handle() interface{}
@see CallbackHandler.Handle()
func (*CallbackEvent) ToJSON ¶
func (ce *CallbackEvent) ToJSON(v interface{}) error
将body字节内容以JSON格式转化
type CallbackHandler ¶
type CallbackHandler struct {
// contains filtered or unexported fields
}
回调事件处理句柄
为某个的事件注册相应的事件处理程序
func NewCallbackHandler ¶
func NewCallbackHandler(masterNum, msgEventLen int, defaultHandle CallbackHandle) (*CallbackHandler, error)
新建回调事件处理句柄(底层消费队列为channel缓冲队列)
func NewCallbackHandlerWithCache ¶
func NewCallbackHandlerWithCache(masterNum, msgEventLen int, defaultHandle CallbackHandle, cache ICache) (*CallbackHandler, error)
新建回调事件处理句柄(底层消费队列为自定义Cache队列) @cache ICache
// 缓存Cache接口
type ICache interface {
// BLPOP key1 timeout(秒)
// 移出并获取列表的第一个元素,
// 如果列表没有元素会阻塞列表直到等待超时或发现可弹出元素为止。
BLPop(key string,timeout int64)(map[string]string, error)
// 在列表尾部中添加一个或多个值
RPush(key string,values ... interface{}) (int64, error)
// 获取列表长度
LLen(key string) (int64, error)
}
func (*CallbackHandler) ConsumerNumGoroutine ¶
func (ch *CallbackHandler) ConsumerNumGoroutine() (master, assistActive int64)
事件队列处理协程数目情况
func (*CallbackHandler) Get ¶
func (ch *CallbackHandler) Get(cc CallbackCommand) (RouterInfo, bool)
获取事件处理路由信息
func (*CallbackHandler) Handle ¶
func (ch *CallbackHandler) Handle(ce *CallbackEvent) interface{}
处理事件
func (*CallbackHandler) InitProducerConsumer ¶
func (ch *CallbackHandler) InitProducerConsumer(masterNum, msgEventLen int, pcType string, cache producerConsumer.ICache) error
@masterNum 主消费线程数目,必须大于等于1 @chanLen 消费信息(事件)队列长度
func (*CallbackHandler) NewCallbackEvent ¶
func (ch *CallbackHandler) NewCallbackEvent(cc CallbackCommand, up *URLParams, body []byte) *CallbackEvent
新建事件
func (*CallbackHandler) Register ¶
func (ch *CallbackHandler) Register(cc CallbackCommand, ri RouterInfo) *CallbackHandler
注册
如果重复注册,新的将覆盖旧的
func (*CallbackHandler) RegisterBeforeHook ¶
func (ch *CallbackHandler) RegisterBeforeHook(beforeHook CallbackHandle) *CallbackHandler
注册钩子
func (*CallbackHandler) RegisterDefaultHandle ¶
func (ch *CallbackHandler) RegisterDefaultHandle(callbackHandle CallbackHandle) *CallbackHandler
注册默认处理程序
func (*CallbackHandler) UnRegister ¶
func (ch *CallbackHandler) UnRegister(cc CallbackCommand) *CallbackHandler
注销事件处理路由信息
type GroupSendMsgBody ¶
type GroupSendMsgBody struct {
SendMsgBody
GroupInfo
Operator_Account string //请求的发起者
Random string // 随机数
}
群聊消息
type GroupType ¶
type GroupType string
私有群(Private):适用于较为私密的聊天场景,群组资料不公开,只能通过邀请的方式加入,类似于微信群。 公开群(Public):适用于公开群组,具有较为严格的管理机制、准入机制,类似于QQ群。 聊天室(ChatRoom):群成员可以随意进出,组织较为松散。 互动直播聊天室(AVChatRoom):适用于互动直播场景,管理上与聊天室相似,但群成员人数无上限;支持以游客身份(不登录)接收消息。
type RouterInfo ¶
type RouterInfo struct {
// 异步或者同步
Async bool
// 如果是异步处理,
// 默认的返回的数据。
// 一般为BaseResponse结构体即可
AsyncResponse interface{}
// 处理句柄
// 事件具体处理的程序。
// 如果同步处理,返回的数据将返回到客户端去,如果异步的话,将会忽略
Handle CallbackHandle
}
事件处理信息和程序
type SendMsgBody ¶
type SendMsgBody struct {
BaseBody
From_Account string
To_Account string
MsgBody []struct {
MsgType string
MsgContent map[string]interface{}
}
}
发单聊消息
type URLParams ¶
type URLParams struct {
// APP在云通讯申请的Appid。
SdkAppid string `json:"SdkAppid"`
// 回调命令字。
CallbackCommand CallbackCommand `json:"CallbackCommand"`
//固定为:json。对应:contenttype
ContentType string `json:"ContentType"`
// 客户端IP地址
ClientIP string `json:"ClientIP"`
// 客户端平台。对应不同的平台类型,
// 可能的取值有: RESTAPI(使用REST API发送请求)、
// Web(使用Web SDK发送请求)、
// Android、
// iOS、
// Windows、
// Mac、
// Unkown(使用未知类型的设备发送请求)。
OptPlatform OptPlatform `json:"OptPlatform"`
}
腾讯云在发起回调时,会在APP提供的URL之后增加如下几个参数: @link https://www.qcloud.com/doc/product/269/1522 回调协议
Click to show internal directories.
Click to hide internal directories.
