Documentation ¶
Index ¶
- Variables
- func DefaultDataFilter(data []byte, next DataDispatcherFunc) (err error)
- func DefaultPacketFilter(pkg interface{}, next PacketDispatcherFunc) (err error)
- func InstallInnerOptionsWatchDog(dog func(cc *InnerOptions))
- func InstallProcessOptionsWatchDog(dog func(cc *ProcessOptions))
- func SetRouter(r Router)
- type AtomicNumber
- type Context
- type ContextPool
- type DataDispatcherFilter
- type DataDispatcherFunc
- type InnerOption
- func WithInnerOptionBindData(v interface{}) InnerOption
- func WithInnerOptionContextPool(v ContextPool) InnerOption
- func WithInnerOptionLoad(v AtomicNumber) InnerOption
- func WithInnerOptionOutput(v io.Writer) InnerOption
- func WithInnerOptionParentCtx(v context.Context) InnerOption
- func WithInnerOptionRouter(v Router) InnerOption
- func WithInnerOptionSequence(v AtomicNumber) InnerOption
- type InnerOptions
- type MiddlewareFunc
- type MixRouter
- func (r *MixRouter) GetHandlers(in interface{}) (handlers []RouterFunc, err error)
- func (r *MixRouter) NoRouter(rf RouterFunc, mid ...MiddlewareFunc) (err error)
- func (r *MixRouter) Register(uri interface{}, rf RouterFunc, m ...MiddlewareFunc) (err error)
- func (r *MixRouter) Use(m ...MiddlewareFunc)
- type PacketDispatcherFilter
- type PacketDispatcherFunc
- type Process
- type ProcessFilter
- type ProcessOption
- func WithDispatchDataFilter(v DataDispatcherFilter) ProcessOption
- func WithDispatchPacketFilter(v PacketDispatcherFilter) ProcessOption
- func WithFrameLogger(v *zaplog.Logger) ProcessOption
- func WithLoadLimitFilter(v func(req interface{}, count AtomicNumber) bool) ProcessOption
- func WithLogger(v *zaplog.Logger) ProcessOption
- func WithMsgCodec(v message.Codec) ProcessOption
- func WithPacketCodec(v packet.Codec) ProcessOption
- func WithPacketEncode(v packet.Encoder) ProcessOption
- func WithPacketPool(v packet.Pool) ProcessOption
- func WithPacketWraper(v packet.ProtocolWraper) ProcessOption
- type ProcessOptions
- type Processer
- type Router
- type RouterFunc
- type WrapContext
- func (ctx *WrapContext) Abort()
- func (ctx *WrapContext) Bind(body interface{}) (err error)
- func (ctx *WrapContext) Deadline() (deadline time.Time, ok bool)
- func (ctx *WrapContext) Done() <-chan struct{}
- func (ctx *WrapContext) Err() error
- func (ctx *WrapContext) GetReqeustMD() (metadata.MD, error)
- func (ctx *WrapContext) GetRequestPacket() interface{}
- func (ctx *WrapContext) Logger() *zaplog.Logger
- func (ctx *WrapContext) NewEntry(funcName string) *zaplog.LogEntities
- func (ctx *WrapContext) Next(nctx Context)
- func (ctx *WrapContext) Respond(_ context.Context, body interface{}, md metadata.MD) (err error)
- func (ctx *WrapContext) Value(key interface{}) interface{}
- func (ctx *WrapContext) WithCancel() (_ Context, cancel func())
- func (ctx *WrapContext) WithDeadline(d time.Time) (_ Context, cancel func())
- func (ctx *WrapContext) WithLogFields(fields ...zap.Field)
- func (ctx *WrapContext) WithTimeout(timeout time.Duration) (_ Context, cancel func())
- func (ctx *WrapContext) WithValue(key, value interface{}) Context
Constants ¶
This section is empty.
Variables ¶
var ( ErrRouterKeyRepated = errors.New("router key repeated") ErrRouterNotSupport = errors.New("router not found") ErrNotFoundRequest = errors.New("no request packet") )
路由返回通用错误
Functions ¶
func DefaultDataFilter ¶
func DefaultDataFilter(data []byte, next DataDispatcherFunc) (err error)
DefaultPacketDispatcher default packet dispatch filter
func DefaultPacketFilter ¶
func DefaultPacketFilter(pkg interface{}, next PacketDispatcherFunc) (err error)
DefaultPacketDispatcher default packet dispatch filter
func InstallInnerOptionsWatchDog ¶
func InstallInnerOptionsWatchDog(dog func(cc *InnerOptions))
InstallInnerOptionsWatchDog install watch dog
func InstallProcessOptionsWatchDog ¶
func InstallProcessOptionsWatchDog(dog func(cc *ProcessOptions))
InstallProcessOptionsWatchDog install watch dog
Types ¶
type AtomicNumber ¶
type AtomicNumber interface { // Load atomically loads the wrapped value. Load() int64 // Add atomically adds to the wrapped int64 and returns the new value. Add(n int64) int64 // Sub atomically subtracts from the wrapped int64 and returns the new value. Sub(n int64) int64 // Inc atomically increments the wrapped int64 and returns the new value. Inc() int64 // Dec atomically decrements the wrapped int64 and returns the new value. Dec() int64 // Store atomically stores the passed value. Store(n int64) }
type Context ¶
type Context interface { // WithValue wrap context.WithValue WithValue(key, value interface{}) Context // WithValue wrap context.WithCancel WithCancel() (_ Context, cancel func()) // WithValue wrap context.WithDeadline WithDeadline(d time.Time) (_ Context, cancel func()) // WithValue wrap context.WithTimeout WithTimeout(timeout time.Duration) (_ Context, cancel func()) // Deadline wrap context.Context.Deadline Deadline() (deadline time.Time, ok bool) // Done wrap context.Context.Done Done() <-chan struct{} // Err wrap context.Context.Err Err() error // Value wrap context.Context.Value Value(key interface{}) interface{} // GetRequestPacket get request packet GetRequestPacket() interface{} // GetReqeustMD get request metadata GetReqeustMD() (metadata.MD, error) // Bind use for unmarshal packet body Bind(body interface{}) (err error) // Respond write response. Respond(_ context.Context, body interface{}, md metadata.MD) (err error) // Next call next middleware or router func Next(nctx Context) // Abort stop call next Abort() // Logger get logger Logger() *zaplog.Logger // WithLogFields WithLogFields(fields ...zap.Field) // NewEntry new log entry NewEntry(funcName string) *zaplog.LogEntities }
Context 基础
type ContextPool ¶
type ContextPool interface { NewContext(inner *InnerOptions, opts *ProcessOptions, inPkg interface{}, handlers []MiddlewareFunc, loadFlag bool) Context FreeContext(Context) }
var WrapContextPool ContextPool = &wrapContextPool{ Pool: sync.Pool{ New: func() interface{} { return &WrapContext{} }, }, }
type DataDispatcherFilter ¶
type DataDispatcherFilter func(data []byte, next DataDispatcherFunc) (err error)
PacketUnmarshalFilter
func DataDispatcherChain ¶
func DataDispatcherChain(filters ...DataDispatcherFilter) DataDispatcherFilter
type DataDispatcherFunc ¶
DataDispatcherFunc 消息分发 - 未解包
type InnerOption ¶
type InnerOption func(cc *InnerOptions) InnerOption
InnerOption option define
func WithInnerOptionContextPool ¶
func WithInnerOptionContextPool(v ContextPool) InnerOption
Specify Real Context
func WithInnerOptionLoad ¶
func WithInnerOptionLoad(v AtomicNumber) InnerOption
load number interface
func WithInnerOptionOutput ¶
func WithInnerOptionOutput(v io.Writer) InnerOption
Output: write interface(net.Conn)
func WithInnerOptionParentCtx ¶
func WithInnerOptionParentCtx(v context.Context) InnerOption
process context parent
func WithInnerOptionSequence ¶
func WithInnerOptionSequence(v AtomicNumber) InnerOption
Sequence number
type InnerOptions ¶
type InnerOptions struct { // Output: write interface(net.Conn) Output io.Writer // Specify Real Context ContextPool ContextPool // process context parent ParentCtx context.Context // Sequence number Sequence AtomicNumber // load number interface Load AtomicNumber // bind data BindData interface{} // process router. Router Router }
InnerOption use for process
func NewInnerOptions ¶
func NewInnerOptions(opts ...InnerOption) *InnerOptions
NewInnerOptions create options instance.
func (*InnerOptions) ApplyOption ¶
func (cc *InnerOptions) ApplyOption(opts ...InnerOption)
ApplyOption modify options
func (*InnerOptions) GetSetOption ¶
func (cc *InnerOptions) GetSetOption(opt InnerOption) InnerOption
GetSetOption modify and get last option
func (*InnerOptions) SetOption ¶
func (cc *InnerOptions) SetOption(opt InnerOption)
SetOption modify options
type MiddlewareFunc ¶
type MiddlewareFunc func(Context)
MiddlewareFunc is middleware or router functions
type MixRouter ¶
type MixRouter struct {
// contains filtered or unexported fields
}
MixRouter 混合路由. 优先使用RequestID.(内部功能也使用RequestID) 路由必须先注册,再使用. 已经开始使用之后,路由不能再修改.(内部无锁)
func (*MixRouter) GetHandlers ¶
func (r *MixRouter) GetHandlers(in interface{}) (handlers []RouterFunc, err error)
GetHandlers 获取请求对应处理函数
func (*MixRouter) NoRouter ¶
func (r *MixRouter) NoRouter(rf RouterFunc, mid ...MiddlewareFunc) (err error)
NoRouter 未设置路由请求
func (*MixRouter) Register ¶
func (r *MixRouter) Register(uri interface{}, rf RouterFunc, m ...MiddlewareFunc) (err error)
type PacketDispatcherFilter ¶
type PacketDispatcherFilter func(pkg interface{}, next PacketDispatcherFunc) (err error)
PacketUnmarshalFilter
func PacketDispatcherChain ¶
func PacketDispatcherChain(filters ...PacketDispatcherFilter) PacketDispatcherFilter
type PacketDispatcherFunc ¶
type PacketDispatcherFunc func(pkg interface{}) (err error)
PacketDispatcherFunc 消息分发 - 未解包
type Process ¶
type Process struct { // config Inner *InnerOptions Opts *ProcessOptions Filter ProcessFilter // contains filtered or unexported fields }
Process 通用process 封装
func NewProcess ¶
func NewProcess(inner *InnerOptions, opts *ProcessOptions) Process
type ProcessFilter ¶
type ProcessFilter func(pkg interface{}) (filter bool)
type ProcessOption ¶
type ProcessOption func(cc *ProcessOptions) ProcessOption
ProcessOption option define
func WithDispatchDataFilter ¶
func WithDispatchDataFilter(v DataDispatcherFilter) ProcessOption
dispatch packet data filter
func WithDispatchPacketFilter ¶
func WithDispatchPacketFilter(v PacketDispatcherFilter) ProcessOption
dispatch packet struct filter
func WithLoadLimitFilter ¶
func WithLoadLimitFilter(v func(req interface{}, count AtomicNumber) bool) ProcessOption
load limit. return true to ignore packet.
type ProcessOptions ¶
type ProcessOptions struct { // log interface Logger *zaplog.Logger // frame log FrameLogger *zaplog.Logger // packet pool PacketPool packet.Pool // packet wraper PacketWraper packet.ProtocolWraper // packet encoder PacketEncode packet.Encoder // packet codec PacketCodec packet.Codec // message codec MsgCodec message.Codec // dispatch packet data filter DispatchDataFilter DataDispatcherFilter // dispatch packet struct filter DispatchPacketFilter PacketDispatcherFilter // load limit. return true to ignore packet. LoadLimitFilter func(req interface{}, count AtomicNumber) bool }
ProcessOption process option
func NewProcessOptions ¶
func NewProcessOptions(opts ...ProcessOption) *ProcessOptions
NewProcessOptions create options instance.
func (*ProcessOptions) ApplyOption ¶
func (cc *ProcessOptions) ApplyOption(opts ...ProcessOption)
ApplyOption modify options
func (*ProcessOptions) GetSetOption ¶
func (cc *ProcessOptions) GetSetOption(opt ProcessOption) ProcessOption
GetSetOption modify and get last option
func (*ProcessOptions) SetOption ¶
func (cc *ProcessOptions) SetOption(opt ProcessOption)
SetOption modify options
type Router ¶
type Router interface { // Use 设置中间件,在Use之后注册的接口都会使用此中间件 Use(m ...MiddlewareFunc) // NoRouter 未注册路由的默认处理函数 NoRouter(rf RouterFunc, mid ...MiddlewareFunc) (err error) // Register 注册路由 Register(uri interface{}, rf RouterFunc, m ...MiddlewareFunc) (err error) // GetHandlers 获取处理函数接口 GetHandlers(p interface{}) (handlers []RouterFunc, err error) }
Router 路由接口
type WrapContext ¶
type WrapContext struct { // config Inner *InnerOptions Opts *ProcessOptions // SrcContext Context parent is link Context SrcContext context.Context // call chain Index int Handlers []MiddlewareFunc // input packet InPkg interface{} LoadFlag bool // Log context Log *zaplog.Logger // use to free context FreeContext Context }
Context 基础
func (*WrapContext) Bind ¶
func (ctx *WrapContext) Bind(body interface{}) (err error)
Bind use for unmarshal packet body
func (*WrapContext) Deadline ¶
func (ctx *WrapContext) Deadline() (deadline time.Time, ok bool)
Deadline wrap context.Context.Deadline
func (*WrapContext) Done ¶
func (ctx *WrapContext) Done() <-chan struct{}
Done wrap context.Context.Done
func (*WrapContext) GetReqeustMD ¶
func (ctx *WrapContext) GetReqeustMD() (metadata.MD, error)
GetReqeustMD get request metadata
func (*WrapContext) GetRequestPacket ¶
func (ctx *WrapContext) GetRequestPacket() interface{}
GetRequestPacket get request packet
func (*WrapContext) NewEntry ¶
func (ctx *WrapContext) NewEntry(funcName string) *zaplog.LogEntities
NewEntry new log entry
func (*WrapContext) Next ¶
func (ctx *WrapContext) Next(nctx Context)
Next call next middleware or router func
func (*WrapContext) Value ¶
func (ctx *WrapContext) Value(key interface{}) interface{}
Value wrap context.Context.Value
func (*WrapContext) WithCancel ¶
func (ctx *WrapContext) WithCancel() (_ Context, cancel func())
WithValue wrap context.WithCancel
func (*WrapContext) WithDeadline ¶
func (ctx *WrapContext) WithDeadline(d time.Time) (_ Context, cancel func())
WithValue wrap context.WithDeadline
func (*WrapContext) WithLogFields ¶
func (ctx *WrapContext) WithLogFields(fields ...zap.Field)
WithLogFields
func (*WrapContext) WithTimeout ¶
func (ctx *WrapContext) WithTimeout(timeout time.Duration) (_ Context, cancel func())
WithValue wrap context.WithTimeout
func (*WrapContext) WithValue ¶
func (ctx *WrapContext) WithValue(key, value interface{}) Context
WithValue wrap context.WithValue