server

package
v0.0.0-...-cf17eb6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2021 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Modules = make(map[string]ModuleInfo)
)
View Source
var Version = "debug"

Functions

func GetIndex

func GetIndex(in interface{}) (int64, error)

func Init

func Init()

Init 快速初始化

func RegisterModule

func RegisterModule(instance Module)

RegisterModule - 向全局添加 Module

func Run

func Run()

Run 正式开启服务

func StartService

func StartService()

StartService 启动服务 根据 Module 生命周期 此过程应在Login前调用 请勿重复调用

func Stop

func Stop()

Stop 停止所有服务 调用此函数并不会使服务器关闭

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

func (m *Message) Get(key string) (value interface{}, exists bool)

Get returns the value for the given key, ie: (value, true). If the value does not exists it returns (nil, false)

func (*Message) GetString

func (m *Message) GetString(key string) (s string)

GetString 返回string类型的指定键的值

func (*Message) Key

func (m *Message) Key() (key string)

func (*Message) MustGet

func (m *Message) MustGet(key string) interface{}

MustGet 如果键存在,则返回给定键的值,否则panic

func (*Message) Next

func (m *Message) Next()

func (*Message) Set

func (m *Message) Set(key string, value interface{})

func (*Message) Type

func (m *Message) Type() (msgType string)

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

func NewModuleID(namespace, moduleName string) ModuleID

NewModuleID 构造函数,统一生成 ModuleID,避免非法模块名的存在

type ModuleInfo

type ModuleInfo struct {
	// ID 模块的名称
	// 应全局唯一
	ID ModuleID

	// Instance 返回 Module
	Instance Module
}

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
}

func NewMsgEngine

func NewMsgEngine() *MsgEngine

NewMsgEngine 创建一个 MsgEngine 对象

func (*MsgEngine) Serve

func (msgEngine *MsgEngine) Serve(c *gin.Context)

Serve 服务代码 服务类消息 [?] 此处应为 中间件内部调用

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
}
var Instance *Server

type SubscribeEventHandle

type SubscribeEventHandle BasicHandle

type TextMsgHandle

type TextMsgHandle BasicKeyHandle

type UnsubscribeEventHandle

type UnsubscribeEventHandle BasicHandle

type ViewEventHandle

type ViewEventHandle BasicKeyHandle

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL