Documentation ¶
Index ¶
- Variables
- func GetIndex(in interface{}) (int64, error)
- func Init()
- func RegisterModule(instance Module)
- func Run()
- func StartService()
- func Stop()
- type BasicHandle
- type BasicKeyHandle
- type ClickEventHandle
- type HandlerFunc
- type HandlersChain
- type IRoutes
- type Message
- func (m *Message) Get(key string) (value interface{}, exists bool)
- func (m *Message) GetString(key string) (s string)
- func (m *Message) Key() (key string)
- func (m *Message) MustGet(key string) interface{}
- func (m *Message) Next()
- func (m *Message) Set(key string, value interface{})
- func (m *Message) Type() (msgType string)
- type Module
- type ModuleID
- type ModuleInfo
- type MsgEngine
- type RouterGroup
- func (group *RouterGroup) EventClick(key string, handler ...HandlerFunc) IRoutes
- func (group *RouterGroup) EventScan(index int, handler ...HandlerFunc) IRoutes
- func (group *RouterGroup) EventSubscribe(index int, handler ...HandlerFunc) IRoutes
- func (group *RouterGroup) EventUnsubscribe(index int, handler ...HandlerFunc) IRoutes
- func (group *RouterGroup) EventView(key string, handler ...HandlerFunc) IRoutes
- func (group *RouterGroup) Group(baseKey string, middleware ...HandlerFunc) *RouterGroup
- func (group *RouterGroup) Handle(h interface{})
- func (group *RouterGroup) MsgText(key string, index int, handler ...HandlerFunc) IRoutes
- func (group *RouterGroup) Use(middleware ...HandlerFunc) IRoutes
- type ScanEventHandle
- type Server
- type SubscribeEventHandle
- type TextMsgHandle
- type UnsubscribeEventHandle
- type ViewEventHandle
Constants ¶
This section is empty.
Variables ¶
View Source
var (
Modules = make(map[string]ModuleInfo)
)
View Source
var Version = "debug"
Functions ¶
Types ¶
type BasicHandle ¶
type BasicHandle struct { Index int // 回复优先级 数字越大优先级越高 Handlers HandlersChain }
BasicHandle 包含消息路由必备的内容
type BasicKeyHandle ¶
type BasicKeyHandle struct { Keyword string // 匹配关键字 Pattern *regexp.Regexp // 将 Keyword 预处理为正则对象 BasicHandle }
BasicKeyHandle 包含消息路由必备的内容和Key
type ClickEventHandle ¶
type ClickEventHandle BasicKeyHandle // 本来设计是使用map来匹配这种单一结果的路由 但是为了方便使用group完成花活 所以这么搞了
type HandlerFunc ¶
type HandlerFunc func(msg *Message)
type HandlersChain ¶
type HandlersChain []HandlerFunc
type IRoutes ¶
type IRoutes interface { Group(baseKey string, middleware ...HandlerFunc) *RouterGroup Use(middleware ...HandlerFunc) IRoutes Handle(handle interface{}) MsgText(key string, index int, handler ...HandlerFunc) IRoutes EventClick(key string, handler ...HandlerFunc) IRoutes EventView(key string, handler ...HandlerFunc) IRoutes EventScan(index int, handler ...HandlerFunc) IRoutes EventSubscribe(index int, handler ...HandlerFunc) IRoutes EventUnsubscribe(index int, handler ...HandlerFunc) IRoutes }
IRoutes 定义所有的路由处理接口
type Message ¶
type Message struct { *message.MixMessage Reply *message.Reply // Keys 是每个请求所特有的键值对 Keys map[string]interface{} // 这个锁保护 Keys map sync.RWMutex //记录当前handler序号 Index int8 // contains filtered or unexported fields }
Message 最初只是为了加两个方法上去 现在作为上下文
func (*Message) Get ¶
Get returns the value for the given key, ie: (value, true). If the value does not exists it returns (nil, false)
type Module ¶
type Module interface { GetModuleInfo() ModuleInfo // Init 初始化 // 待所有 Module 初始化完成后 // 进行服务注册 Serve Init() // PostInit 第二次初始化 // 调用该函数时,所有 Module 都已完成第一段初始化过程 // 方便进行跨Module调用 PostInit() // Serve 向Bot注册服务函数 // 结束后调用 Start Serve(server *Server) // Start 启用Module // 此处调用为 // “` go // go Start() // “` // 结束后正式开启服务 Start(server *Server) // Stop 应用结束时对所有 Module 进行通知 // 在此进行资源回收 Stop(server *Server, wg *sync.WaitGroup) }
type ModuleID ¶
type ModuleID interface { Namespace() string // 命名空间,一般用开发者名字,请使用 小写 并用 _ 代替空格 ModuleName() string // 模块名,一般用包名 String() string }
ModuleID 模块ID 请使用 小写 并用 _ 代替空格 Example: - atom.pong
func NewModuleID ¶
NewModuleID 构造函数,统一生成 ModuleID,避免非法模块名的存在
type ModuleInfo ¶
ModuleInfo 模块信息
func GetModule ¶
func GetModule(id ModuleID) (ModuleInfo, error)
GetModule - 获取一个已注册的 Module 的 ModuleInfo
func (ModuleInfo) String ¶
func (mi ModuleInfo) String() string
type MsgEngine ¶
type MsgEngine struct { RouterGroup // contains filtered or unexported fields }
type RouterGroup ¶
type RouterGroup struct { Handlers HandlersChain // contains filtered or unexported fields }
func (*RouterGroup) EventClick ¶
func (group *RouterGroup) EventClick(key string, handler ...HandlerFunc) IRoutes
func (*RouterGroup) EventScan ¶
func (group *RouterGroup) EventScan(index int, handler ...HandlerFunc) IRoutes
func (*RouterGroup) EventSubscribe ¶
func (group *RouterGroup) EventSubscribe(index int, handler ...HandlerFunc) IRoutes
func (*RouterGroup) EventUnsubscribe ¶
func (group *RouterGroup) EventUnsubscribe(index int, handler ...HandlerFunc) IRoutes
func (*RouterGroup) EventView ¶
func (group *RouterGroup) EventView(key string, handler ...HandlerFunc) IRoutes
func (*RouterGroup) Group ¶
func (group *RouterGroup) Group(baseKey string, middleware ...HandlerFunc) *RouterGroup
func (*RouterGroup) Handle ¶
func (group *RouterGroup) Handle(h interface{})
func (*RouterGroup) MsgText ¶
func (group *RouterGroup) MsgText(key string, index int, handler ...HandlerFunc) IRoutes
func (*RouterGroup) Use ¶
func (group *RouterGroup) Use(middleware ...HandlerFunc) IRoutes
type ScanEventHandle ¶
type ScanEventHandle BasicHandle
type Server ¶
type Server struct { HttpEngine *gin.Engine WechatEngine *officialaccount.OfficialAccount MsgEngine *MsgEngine ReplyCount int }
var Instance *Server
type SubscribeEventHandle ¶
type SubscribeEventHandle BasicHandle
type TextMsgHandle ¶
type TextMsgHandle BasicKeyHandle
type UnsubscribeEventHandle ¶
type UnsubscribeEventHandle BasicHandle
type ViewEventHandle ¶
type ViewEventHandle BasicKeyHandle
Click to show internal directories.
Click to hide internal directories.