Documentation
¶
Index ¶
- Constants
- Variables
- func AddLogger(logger ILogger)
- func AddVar[T Var](name string, def T, usage string)
- func BeforeExitCh(name string) chan<- struct{}
- func BeforeExitFn(name string, fn util.Fn)
- func BindEvent(name string, handler EventHandler[util.M])
- func CodecSpawn[T any](svc TSvc, mtd TCode) (T, *util.Err)
- func CodecSpawnRes[T any](svc TSvc, mtd TCode) (T, *util.Err)
- func Debug(str string, params util.M)
- func DispatchEvent(name string, data any)
- func Error(err *util.Err)
- func Error2(code util.TErrCode, m util.M)
- func Error3(code util.TErrCode, e error)
- func Fatal(err *util.Err)
- func Fatal2(code util.TErrCode, m util.M)
- func Fatal3(code util.TErrCode, e error)
- func GetCaller(skip int) string
- func GetVar[T Var](name string) (T, bool)
- func GoWaitGroup(secs int, wg *sync.WaitGroup, over util.FnBool, ticker util.FnInt)
- func Info(str string, params util.M)
- func LevelToStr(l TLevel) string
- func ParseVar()
- func SetCallerSkip(skip int)
- func SetCodec(codec ICodec)
- func SetGate(gate IGate)
- func SetLogDefParams(params util.M)
- func SetNode(node INode)
- func SetPacker(packer IPacker)
- func SetRouter(router IRouter)
- func SplitSvcCode(sc TSvcCode) (TSvc, TCode)
- func TC(pid int64, params util.M, exclude bool) int64
- func TD(tid int64, msg string, params util.M)
- func TE(tid int64, err *util.Err)
- func TE2(tid int64, code util.TErrCode, m util.M)
- func TE3(tid int64, code util.TErrCode, e error)
- func TF(tid int64, err *util.Err)
- func TF2(tid int64, code util.TErrCode, m util.M)
- func TI(tid int64, msg string, params util.M)
- func TW(tid int64, err *util.Err)
- func TW2(tid int64, code util.TErrCode, m util.M)
- func TW3(tid int64, code util.TErrCode, e error)
- func UnbindEvent(name string, handler EventHandler[util.M])
- func WaitExit()
- func WaitGroup(secs int, wg *sync.WaitGroup, ticker util.FnInt) bool
- func Warn(err *util.Err)
- func Warn2(code util.TErrCode, m util.M)
- func Warn3(code util.TErrCode, e error)
- type AgentBytesToBytes
- type AgentBytesToBytesErr
- type AgentOpt
- type AgentOption
- type AgentRWMode
- type Dispatcher
- type EWorker
- type EventHandler
- type EvtRouterConnected
- type EvtRouterDisconnected
- type EvtStart
- type EvtStop
- type EvtSvcConnected
- type EvtSvcDisconnected
- type FnAgent
- type FnAgentBool
- type FnAgentBytes
- type FnAgentErr
- type FnRcvPkt
- type FnRcvPus
- type FnRcvReq
- type GateReceiver
- type IAgent
- type ICodec
- type IDialer
- type IGate
- type IListener
- type ILogger
- type INode
- type INodeDialer
- type INodeHandler
- type IPacker
- type IRcvNotice
- type IRcvPkt
- type IRcvPush
- type IRcvRequest
- type IRouter
- type IService
- type ISndNotice
- type ISndPacket
- type ISndPush
- type ISndRequest
- type NodeDialerToBool
- type NodeMeta
- type NotifyHandler
- type PacketToStr
- type PktToKey
- type TCode
- type TLevel
- type TSvc
- type TSvcCode
- type Var
- type WorkerFn
Constants ¶
View Source
const ( ModeDebug = "debug" ModeDev = "dev" ModeProd = "prod" )
View Source
const ( N_Service_Start = "service_start" N_Service_Stop = "service_stop" )
View Source
const ( Evt_Start = "start" Evt_Stop = "stop" Evt_Svc_Connected = "svc_connected" Evt_Svc_Disonnected = "svc_disconnected" )
View Source
const ( SDebug = "debug" SInfo = "info" SWarn = "warn" SError = "error" SFatal = "fatal" )
View Source
const (
DefTimeFormatter = "2006-01-02 15:04:05.999"
)
Variables ¶
View Source
var ( TestLevels = []TLevel{TDebug, TInfo, TWarn, TError, TFatal} DevLevels = []TLevel{TInfo, TWarn, TError, TFatal} ProdLevels = []TLevel{TWarn, TError, TFatal} )
View Source
var Mod = TSvcCode(1000)
Functions ¶
func BeforeExitCh ¶
func BeforeExitCh(name string) chan<- struct{}
func BeforeExitFn ¶
func DispatchEvent ¶
func GoWaitGroup ¶
func LevelToStr ¶
func SetCallerSkip ¶
func SetCallerSkip(skip int)
func SetLogDefParams ¶
func SplitSvcCode ¶
func UnbindEvent ¶
func UnbindEvent(name string, handler EventHandler[util.M])
Types ¶
type AgentBytesToBytes ¶
type AgentOpt ¶
type AgentOpt struct { PacketMaxCap uint32 //最大包长 PacketMinCap uint32 //包长最小容量 OnErr util.FnErr //处理错误 DeadlineSecs int AgentMode AgentRWMode HeadLen uint32 }
AgentOpt Agent代理选项
type AgentOption ¶
type AgentOption func(o *AgentOpt)
AgentOpt Agent代理选项
func AgentDeadline ¶
func AgentDeadline(secs int) AgentOption
func AgentHeadLen ¶
func AgentHeadLen(length uint32) AgentOption
func AgentMode ¶
func AgentMode(mode AgentRWMode) AgentOption
func AgentPacketMaxCap ¶
func AgentPacketMaxCap(packetMaxCap uint32) AgentOption
AgentPacketMaxCap 最大包长
func AgentPacketMinCap ¶
func AgentPacketMinCap(packetMinCap uint32) AgentOption
AgentPacketMinCap 包长最小容量
type Dispatcher ¶
type Dispatcher[T any] struct { // contains filtered or unexported fields }
func Event ¶
func Event() *Dispatcher[util.M]
func NewDispatcher ¶
func NewDispatcher[T any](data T) *Dispatcher[T]
func (*Dispatcher[T]) Bind ¶
func (d *Dispatcher[T]) Bind(name string, handler EventHandler[T])
func (*Dispatcher[T]) Dispatch ¶
func (d *Dispatcher[T]) Dispatch(name string, data any)
func (*Dispatcher[T]) Unbind ¶
func (d *Dispatcher[T]) Unbind(name string, handler EventHandler[T])
type EventHandler ¶
type EvtRouterDisconnected ¶
type EvtSvcDisconnected ¶
type FnAgentBool ¶
type FnAgentBytes ¶
type FnAgentErr ¶
type FnRcvReq ¶
type FnRcvReq func(IRcvRequest)
type GateReceiver ¶
type IAgent ¶
type IAgent interface { SetHead(key string, val any) SetHeads(m util.M) GetHead(key string) (any, bool) DelHead(keys ...string) CopyHead(m util.M) SetCache(key string, val any) SetCaches(m util.M) GetCache(key string) (any, bool) DelCache(keys ...string) CopyCache(m util.M) Id() string SetId(id string) Addr() string Host() string // Enable 状态 Enable() *util.Enable // Send 发送数据 Send(bytes []byte) *util.Err // Dispose 释放 Dispose() BindConnected(fn FnAgent) BindDisconnected(fn FnAgentErr) }
IAgent 连接代理接口
type ICodec ¶
type ICodec interface { PbMarshal(obj util.IMsg) ([]byte, *util.Err) PbUnmarshal(data []byte, msg util.IMsg) *util.Err PbUnmarshal2(svc TSvc, mtd TCode, data []byte) (util.IMsg, *util.Err) JsonMarshal(obj util.IMsg) ([]byte, *util.Err) JsonUnmarshal(data []byte, msg util.IMsg) *util.Err JsonUnmarshal2(svc TSvc, mtd TCode, data []byte) (util.IMsg, *util.Err) Spawn(svc TSvc, mtd TCode) (util.IMsg, *util.Err) SpawnRes(svc TSvc, mtd TCode) (util.IMsg, *util.Err) BindFac(svc TSvc, mtd TCode, fac util.ToMsg) BindReqToRes(svc TSvc, req, res TCode) ReqToResCode(svc TSvc, req TCode) (TCode, *util.Err) MsgToSvcCode(msg util.IMsg) (svc TSvc, code TCode) }
type IDialer ¶
type IDialer interface { // Name 拨号器名称 Name() string // Connect 连接远程服务器 Connect(ctx context.Context) *util.Err // Agent 连接代理 Agent() IAgent }
IDialer 拨号器接口
type IGate ¶
type IGate interface { Dispose() *util.Err Send(tid int64, id string, bytes []byte, handler util.FnBool) AddrSend(tid int64, addr string, bytes []byte, handler util.FnBool) MultiSend(tid int64, idToPayload map[string][]byte, handler util.FnMapBool) MultiAddrSend(tid int64, addrToPayload map[string][]byte, handler util.FnMapBool) AllSend(tid int64, bytes []byte) CloseWithId(tid int64, id string, removeHeadKeys, removeCacheKeys []string) CloseWithAddr(tid int64, addr string, removeHeadKeys, removeCacheKeys []string) UpdateHeadCache(tid int64, id string, head, cache util.M, handler util.FnBool) UpdateAddrHeadCache(tid int64, addr string, head, cache util.M, handler util.FnBool) RemoveHeadCache(tid int64, addr string, head, cache []string, handler util.FnBool) RemoveAddrHeadCache(tid int64, addr string, head, cache []string, handler util.FnBool) GetHeadCache(tid int64, id string, fn util.FnM2Bool) GetAddrHeadCache(tid int64, id string, fn util.FnM2Bool) SetRoles(m map[TSvcCode][]int64) Authenticate(mask int64, svc TSvc, code TCode) bool }
type IListener ¶
type IListener interface { // Addr 监听地址 Addr() string Port() int // Start 开始监听 Start() *util.Err // Close 关闭监听 Close() }
IListener 监听器
type ILogger ¶
type ILogger interface { // Log 记录日志 Log(level TLevel, msg, caller string, stack []byte, params util.M) // Trace 标记链路 Trace(pid, tid int64, caller string, params util.M) // Span 链路日志 Span(level TLevel, tid int64, msg, caller string, stack []byte, params util.M) }
ILogger 日志
type INode ¶
type INode interface { Init() *util.Err Connect(ip string, port int, svc TSvc, nodeId int64, ver string, head util.M) Disconnect(svc TSvc, id int64) Push(pus ISndPush) PushNode(nodeId int64, pus ISndPush) Request(req ISndRequest) RequestNode(nodeId int64, req ISndRequest) Notify(ntf ISndNotice) ReceiveWatchNotice(nodeId int64, methods []TCode) SendToNode(nodeId int64, bytes []byte, fnErr util.FnErr) }
type INodeDialer ¶
type INodeHandler ¶
type IPacker ¶
type IPacker interface { PackWatchNotify(id int64, methods []TCode) []byte UnpackWatchNotify(bytes []byte) (id int64, methods []TCode, err *util.Err) PackPush(tid int64, pus ISndPush) ([]byte, *util.Err) UnpackPush(bytes []byte, pkg IRcvPush) (err *util.Err) UnpackPushBytes(bytes []byte, head util.M) (tid int64, json bool, payload []byte, err *util.Err) PackRequest(tid int64, req ISndRequest) ([]byte, *util.Err) UnpackRequest(bytes []byte, pkg IRcvRequest) (err *util.Err) PackResponseOk(tid int64, head util.M, pkt []byte) ([]byte, *util.Err) UnpackResponseOk(bytes []byte, head util.M) (tid int64, payload []byte, err *util.Err) PackResponseFail(tid int64, head util.M, code uint16) ([]byte, *util.Err) UnpackResponseFail(bytes []byte, head util.M) (tid int64, code uint16, readErr *util.Err) PackNotify(tid int64, ntf ISndNotice) ([]byte, *util.Err) UnpackNotify(bytes []byte, pkg IRcvNotice) (err *util.Err) PackM(m util.M) ([]byte, *util.Err) UnpackM(bytes []byte, m util.M) (err *util.Err) }
type IRcvNotice ¶
type IRcvNotice interface { IRcvPkt }
type IRcvPkt ¶
type IRcvPkt interface { SenderId() int64 Tid() int64 Svc() TSvc Code() TCode Head() util.M HeadId() string Json() bool Msg() util.IMsg SetWorker(typ EWorker, key string) Worker() EWorker WorkerKey() string InitWithBytes(msgType uint8, tid int64, head util.M, json bool, bytes []byte) *util.Err InitWithMsg(msgType uint8, tid int64, head util.M, json bool, msg util.IMsg) Complete() Err(err *util.Err) Err2(code util.TErrCode, m util.M) Err3(code util.TErrCode, e error) }
type IRouter ¶
type IRouter interface { AddRequest(req ISndRequest) DelRequest(tid int64) BindPus(svc TSvc, code TCode, fn FnRcvPus) BindReq(svc TSvc, code TCode, fn FnRcvReq) OnPush(pkt IRcvPush) OnRequest(pkt IRcvRequest) OnResponseOk(tid int64, head util.M, msg util.IMsg) OnResponseOkBytes(tid int64, head util.M, bytes []byte) OnResponseFail(tid int64, head util.M, code uint16) WatchNotice(msg util.IMsg, handler NotifyHandler) GetWatchCodes(svc TSvc) ([]TCode, bool) OnNotice(pkt IRcvNotice) }
type ISndNotice ¶
type ISndNotice interface { ISndPacket }
type ISndPacket ¶
type ISndPush ¶
type ISndPush interface { ISndPacket }
type ISndRequest ¶
type ISndRequest interface { ISndPacket SetBytesHandler(fail util.FnInt64MUint16, ok util.FnInt64MBytes) SetHandler(fail util.FnInt64MUint16, ok util.FnInt64MMsg) OkBytes(head util.M, bytes []byte) Ok(head util.M, msg util.IMsg) Fail(head util.M, code uint16) }
type NodeDialerToBool ¶
type NodeDialerToBool func(INodeDialer) bool
type NodeMeta ¶
type NodeMeta struct { Ip string Port int NodeId int64 StartTime int64 Data util.M Mode string Services map[TSvc]string }
func GetNodeMeta ¶
func GetNodeMeta() *NodeMeta
func (*NodeMeta) AddService ¶
func (*NodeMeta) HasService ¶
type NotifyHandler ¶
type NotifyHandler func(pkt IRcvNotice)
type PacketToStr ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.