Documentation
¶
Index ¶
- Variables
- func CheckInvokeCBFunc(cbFunc HandlerCBFunc, e error, result interface{})
- func FormaterGetInArgIndex(formater IAPIFormater) int
- func SafeCall(handler *Handler, args []reflect.Value, cbFunc HandlerCBFunc)
- type APICollection
- func (s *APICollection) AddReqReply(reqId int, args interface{})
- func (self *APICollection) Build() error
- func (self *APICollection) Call(route string, args []byte, cbFunc HandlerCBFunc, ext interface{}) error
- func (self *APICollection) HasMethod(route string) bool
- func (self *APICollection) Register(e IAPIEntry, options ...Option)
- func (self *APICollection) SetFormater(formater IAPIFormater)
- type APIContainer
- type APIEntries
- type APIEntry
- type BaseAPIEntry
- type DefaultFormater
- type DummySession
- type EntryWithOptions
- type Handler
- type HandlerCBFunc
- type IAPIEntry
- type IAPIFormater
- type IHandlerSession
- type Option
Constants ¶
This section is empty.
Variables ¶
var (
TypeOfSession = reflect.TypeOf((*IHandlerSession)(nil)).Elem()
)
Functions ¶
func CheckInvokeCBFunc ¶
func CheckInvokeCBFunc(cbFunc HandlerCBFunc, e error, result interface{})
func FormaterGetInArgIndex ¶
func FormaterGetInArgIndex(formater IAPIFormater) int
Types ¶
type APICollection ¶
type APICollection struct { Containers map[string]*APIContainer Entries *APIEntries // contains filtered or unexported fields }
func (*APICollection) AddReqReply ¶
func (s *APICollection) AddReqReply(reqId int, args interface{})
序列化
func (*APICollection) Build ¶
func (self *APICollection) Build() error
func (*APICollection) Call ¶
func (self *APICollection) Call(route string, args []byte, cbFunc HandlerCBFunc, ext interface{}) error
Call *
- 1. 转发给对应的Service
- 2. 按目标参数类型反序列化
- cb(error, []byte result)
- 出入口都是[]byte (json序列化)
- ext
- 一个自定义参数,目前是前端接口的session * *
- 将请求转发给底层的各接口执行
- @param route{string} 服务.method路由字符串
- @param args{[]byte} 请求参数流化的数据(json)
- @param cbFunc{HandlerCBFunc} 执行完后的回调
- func(e error, outArg interface{})
- error 是否执行错误
- outArt json序列化的返回值
- @param ext{interace{}} 自定义参数,server:前端接口是session
func (*APICollection) HasMethod ¶
func (self *APICollection) HasMethod(route string) bool
func (*APICollection) Register ¶
func (self *APICollection) Register(e IAPIEntry, options ...Option)
func (*APICollection) SetFormater ¶
func (self *APICollection) SetFormater(formater IAPIFormater)
type APIContainer ¶
type APIContainer struct { Name string // name of service Type reflect.Type // type of the receiver Receiver reflect.Value // receiver of methods for the service // "someMethod": Handler Handlers map[string]*Handler // registered methods Options options // options // contains filtered or unexported fields }
基于入口对象分析构建而成
func NewContainer ¶
func NewContainer(entry IAPIEntry, opts ...Option) *APIContainer
TODO: 目标函数的格式和调用 抽象出来 便于 远程接口和客户端接口使用
func (*APIContainer) CallMethod ¶
func (self *APIContainer) CallMethod(formater IAPIFormater, method string, msg []byte, cbFunc HandlerCBFunc, ext interface{}) error
查找Handler 调用具体函数,会将[]byte数据反序列化成参数结构 返回的数据结构也会被序列化成[]byte *
- @param formater{IAPIFormater} 用于提供接口类型差异化比如handler和remote
- @param method{string} 方法名
- @param msg{[]byte} 此接口负责反序列化成接口参数结构
- @param cbFunc{HandlerCBFunc}
- cb(e error, outArg interface{})
- e 错误
- outArg 接口返回的对象
- (此函数负责序列化,返回出去)
- @param ext{interface{}} 见collection说明
func (*APIContainer) ExtractHandler ¶
func (self *APIContainer) ExtractHandler(formater IAPIFormater) error
ExtractHandler extract the set of methods from the receiver value which satisfy the following conditions: - exported method of exported type - two arguments, both of exported type - the first argument is *session.Session - the second argument is []byte or a pointer
func (*APIContainer) HasMethod ¶
func (self *APIContainer) HasMethod(method string) bool
type APIEntries ¶
type APIEntries struct {
// contains filtered or unexported fields
}
func (*APIEntries) List ¶
func (self *APIEntries) List() []EntryWithOptions
List returns all components with it's options
func (*APIEntries) Register ¶
func (self *APIEntries) Register(e IAPIEntry, options ...Option)
Register registers a component to hub with options
type APIEntry ¶
type APIEntry struct {
BaseAPIEntry
}
type BaseAPIEntry ¶
type BaseAPIEntry struct { }
----------------
func (*BaseAPIEntry) Desc ¶
func (self *BaseAPIEntry) Desc() string
type DefaultFormater ¶
type DefaultFormater struct {
// contains filtered or unexported fields
}
缺省的rpc格式
func (*DefaultFormater) IsValidMethod ¶
func (self *DefaultFormater) IsValidMethod(method reflect.Method) bool
handler函数 3个参数
receiver, pointer, cb
func (*DefaultFormater) MakeCallArgs ¶
func (*DefaultFormater) NeedSession ¶
func (self *DefaultFormater) NeedSession() bool
type DummySession ¶
type DummySession struct { }
func (*DummySession) Handle ¶
func (self *DummySession) Handle()
func (*DummySession) Reserve ¶
func (self *DummySession) Reserve()
type EntryWithOptions ¶
type Handler ¶
type Handler struct { // 对应的函数 // 函数参数 receiver, arg, handlerCBFunc Method reflect.Method // 参数1 receiver // 参数2类型 ArgsType reflect.Type }
对应一个函数
type HandlerCBFunc ¶
type HandlerCBFunc func(error, interface{})
type IAPIFormater ¶
type IAPIFormater interface { // 分析是否符合接口需求 IsValidMethod(reflect.Method) bool NeedSession() bool // Receiver, finalArgs, cbFunc MakeCallArgs(reflect.Value, reflect.Value, reflect.Value, interface{}) []reflect.Value }
API格式器 提供分析API,API调用抽象 前端接口和rpc receiver, [session], inArg, cb rpc接口没有session handler接口有session
type Option ¶
type Option func(options *options)
Option used to customize handler
func WithNameFunc ¶
WithNameFunc override handler name by specific function such as: strings.ToUpper/strings.ToLower
func WithSchedulerName ¶
WithSchedulerName set the name of the service scheduler