Versions in this module Expand all Collapse all v0 v0.0.1 Mar 12, 2024 Changes in this version + const DefTimeFormatter + const Evt_Start + const Evt_Stop + const Evt_Svc_Connected + const Evt_Svc_Disonnected + const ModeDebug + const ModeDev + const ModeProd + const N_Service_Start + const N_Service_Stop + const SDebug + const SError + const SFatal + const SInfo + const SWarn + var DevLevels = []TLevel + var Mod = TSvcCode(1000) + var ProdLevels = []TLevel + var TestLevels = []TLevel + 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 CodecSpawnRes[T any](svc TSvc, mtd TCode) (T, *util.Err) + func CodecSpawn[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 func(IAgent, []byte) []byte + type AgentBytesToBytesErr func(IAgent, []byte) ([]byte, *util.Err) + type AgentOpt struct + AgentMode AgentRWMode + DeadlineSecs int + HeadLen uint32 + OnErr util.FnErr + PacketMaxCap uint32 + PacketMinCap uint32 + type AgentOption func(o *AgentOpt) + func AgentDeadline(secs int) AgentOption + func AgentErr(onErr util.FnErr) AgentOption + func AgentHeadLen(length uint32) AgentOption + func AgentMode(mode AgentRWMode) AgentOption + func AgentPacketMaxCap(packetMaxCap uint32) AgentOption + func AgentPacketMinCap(packetMinCap uint32) AgentOption + type AgentRWMode uint8 + const AgentR + const AgentRW + const AgentW + type Dispatcher struct + func Event() *Dispatcher[util.M] + func NewDispatcher[T any](data T) *Dispatcher[T] + func (d *Dispatcher[T]) Bind(name string, handler EventHandler[T]) + func (d *Dispatcher[T]) Dispatch(name string, data any) + func (d *Dispatcher[T]) Unbind(name string, handler EventHandler[T]) + type EWorker uint8 + const EWorkerActive + const EWorkerGlobal + const EWorkerGo + const EWorkerSelf + const EWorkerShare + type EventHandler func(T, any) + type EvtRouterConnected struct + Head util.M + Id int64 + Svc TSvc + type EvtRouterDisconnected struct + Id int64 + Svc TSvc + type EvtStart struct + Wg *sync.WaitGroup + type EvtStop struct + Wg *sync.WaitGroup + type EvtSvcConnected struct + Head util.M + Id int64 + Svc TSvc + type EvtSvcDisconnected struct + Id int64 + Svc TSvc + type FnAgent func(IAgent) + type FnAgentBool func(IAgent, bool) + type FnAgentBytes func(IAgent, []byte) + type FnAgentErr func(IAgent, *util.Err) + type FnRcvPkt func(IRcvPkt) + type FnRcvPus func(IRcvPush) + type FnRcvReq func(IRcvRequest) + type GateReceiver func(agent IAgent, svc, method string, head util.M, body []byte, fnErr util.FnErr) + type IAgent interface + Addr func() string + BindConnected func(fn FnAgent) + BindDisconnected func(fn FnAgentErr) + CopyCache func(m util.M) + CopyHead func(m util.M) + DelCache func(keys ...string) + DelHead func(keys ...string) + Dispose func() + Enable func() *util.Enable + GetCache func(key string) (any, bool) + GetHead func(key string) (any, bool) + Host func() string + Id func() string + Send func(bytes []byte) *util.Err + SetCache func(key string, val any) + SetCaches func(m util.M) + SetHead func(key string, val any) + SetHeads func(m util.M) + SetId func(id string) + type ICodec interface + BindFac func(svc TSvc, mtd TCode, fac util.ToMsg) + BindReqToRes func(svc TSvc, req, res TCode) + JsonMarshal func(obj util.IMsg) ([]byte, *util.Err) + JsonUnmarshal func(data []byte, msg util.IMsg) *util.Err + JsonUnmarshal2 func(svc TSvc, mtd TCode, data []byte) (util.IMsg, *util.Err) + MsgToSvcCode func(msg util.IMsg) (svc TSvc, code TCode) + PbMarshal func(obj util.IMsg) ([]byte, *util.Err) + PbUnmarshal func(data []byte, msg util.IMsg) *util.Err + PbUnmarshal2 func(svc TSvc, mtd TCode, data []byte) (util.IMsg, *util.Err) + ReqToResCode func(svc TSvc, req TCode) (TCode, *util.Err) + Spawn func(svc TSvc, mtd TCode) (util.IMsg, *util.Err) + SpawnRes func(svc TSvc, mtd TCode) (util.IMsg, *util.Err) + func Codec() ICodec + type IDialer interface + Agent func() IAgent + Connect func(ctx context.Context) *util.Err + Name func() string + type IGate interface + AddrSend func(tid int64, addr string, bytes []byte, handler util.FnBool) + AllSend func(tid int64, bytes []byte) + Authenticate func(mask int64, svc TSvc, code TCode) bool + CloseWithAddr func(tid int64, addr string, removeHeadKeys, removeCacheKeys []string) + CloseWithId func(tid int64, id string, removeHeadKeys, removeCacheKeys []string) + Dispose func() *util.Err + GetAddrHeadCache func(tid int64, id string, fn util.FnM2Bool) + GetHeadCache func(tid int64, id string, fn util.FnM2Bool) + MultiAddrSend func(tid int64, addrToPayload map[string][]byte, handler util.FnMapBool) + MultiSend func(tid int64, idToPayload map[string][]byte, handler util.FnMapBool) + RemoveAddrHeadCache func(tid int64, addr string, head, cache []string, handler util.FnBool) + RemoveHeadCache func(tid int64, addr string, head, cache []string, handler util.FnBool) + Send func(tid int64, id string, bytes []byte, handler util.FnBool) + SetRoles func(m map[TSvcCode][]int64) + UpdateAddrHeadCache func(tid int64, addr string, head, cache util.M, handler util.FnBool) + UpdateHeadCache func(tid int64, id string, head, cache util.M, handler util.FnBool) + func Gate() IGate + type IListener interface + Addr func() string + Close func() + Port func() int + Start func() *util.Err + type ILogger interface + Log func(level TLevel, msg, caller string, stack []byte, params util.M) + Span func(level TLevel, tid int64, msg, caller string, stack []byte, params util.M) + Trace func(pid, tid int64, caller string, params util.M) + type INode interface + Connect func(ip string, port int, svc TSvc, nodeId int64, ver string, head util.M) + Disconnect func(svc TSvc, id int64) + Init func() *util.Err + Notify func(ntf ISndNotice) + Push func(pus ISndPush) + PushNode func(nodeId int64, pus ISndPush) + ReceiveWatchNotice func(nodeId int64, methods []TCode) + Request func(req ISndRequest) + RequestNode func(nodeId int64, req ISndRequest) + SendToNode func(nodeId int64, bytes []byte, fnErr util.FnErr) + func Node() INode + type INodeDialer interface + Dialer func() IDialer + Head func() util.M + NodeId func() int64 + Send func(bytes []byte, fnErr util.FnErr) + Svc func() TSvc + type INodeHandler interface + Receive func(agent IAgent, bytes []byte) + type IPacker interface + PackM func(m util.M) ([]byte, *util.Err) + PackNotify func(tid int64, ntf ISndNotice) ([]byte, *util.Err) + PackPush func(tid int64, pus ISndPush) ([]byte, *util.Err) + PackRequest func(tid int64, req ISndRequest) ([]byte, *util.Err) + PackResponseFail func(tid int64, head util.M, code uint16) ([]byte, *util.Err) + PackResponseOk func(tid int64, head util.M, pkt []byte) ([]byte, *util.Err) + PackWatchNotify func(id int64, methods []TCode) []byte + UnpackM func(bytes []byte, m util.M) (err *util.Err) + UnpackNotify func(bytes []byte, pkg IRcvNotice) (err *util.Err) + UnpackPush func(bytes []byte, pkg IRcvPush) (err *util.Err) + UnpackPushBytes func(bytes []byte, head util.M) (tid int64, json bool, payload []byte, err *util.Err) + UnpackRequest func(bytes []byte, pkg IRcvRequest) (err *util.Err) + UnpackResponseFail func(bytes []byte, head util.M) (tid int64, code uint16, readErr *util.Err) + UnpackResponseOk func(bytes []byte, head util.M) (tid int64, payload []byte, err *util.Err) + UnpackWatchNotify func(bytes []byte) (id int64, methods []TCode, err *util.Err) + func Packer() IPacker + type IRcvNotice interface + type IRcvPkt interface + Code func() TCode + Complete func() + Err func(err *util.Err) + Err2 func(code util.TErrCode, m util.M) + Err3 func(code util.TErrCode, e error) + Head func() util.M + HeadId func() string + InitWithBytes func(msgType uint8, tid int64, head util.M, json bool, bytes []byte) *util.Err + InitWithMsg func(msgType uint8, tid int64, head util.M, json bool, msg util.IMsg) + Json func() bool + Msg func() util.IMsg + SenderId func() int64 + SetWorker func(typ EWorker, key string) + Svc func() TSvc + Tid func() int64 + Worker func() EWorker + WorkerKey func() string + type IRcvPush interface + type IRcvRequest interface + Fail func(code uint16) + Ok func(msg util.IMsg) + type IRouter interface + AddRequest func(req ISndRequest) + BindPus func(svc TSvc, code TCode, fn FnRcvPus) + BindReq func(svc TSvc, code TCode, fn FnRcvReq) + DelRequest func(tid int64) + GetWatchCodes func(svc TSvc) ([]TCode, bool) + OnNotice func(pkt IRcvNotice) + OnPush func(pkt IRcvPush) + OnRequest func(pkt IRcvRequest) + OnResponseFail func(tid int64, head util.M, code uint16) + OnResponseOk func(tid int64, head util.M, msg util.IMsg) + OnResponseOkBytes func(tid int64, head util.M, bytes []byte) + WatchNotice func(msg util.IMsg, handler NotifyHandler) + func Router() IRouter + type IService interface + Dispose func() + Shutdown func() + Start func() + Svc func() TSvc + type ISndNotice interface + type ISndPacket interface + Code func() TCode + Dispose func() + GetSvcNodeId func() (int64, bool) + Head func() util.M + InitHead func() + Json func() bool + Msg func() util.IMsg + Payload func() []byte + Pid func() int64 + Svc func() TSvc + Tid func() int64 + type ISndPush interface + type ISndRequest interface + Fail func(head util.M, code uint16) + Ok func(head util.M, msg util.IMsg) + OkBytes func(head util.M, bytes []byte) + SetBytesHandler func(fail util.FnInt64MUint16, ok util.FnInt64MBytes) + SetHandler func(fail util.FnInt64MUint16, ok util.FnInt64MMsg) + type NodeDialerToBool func(INodeDialer) bool + type NodeMeta struct + Data util.M + Ip string + Mode string + NodeId int64 + Port int + Services map[TSvc]string + StartTime int64 + func GetNodeMeta() *NodeMeta + func (n *NodeMeta) AddService(svc TSvc, ver string) + func (n *NodeMeta) HasService(svc TSvc) bool + func (n *NodeMeta) Init(id int64) + type NotifyHandler func(pkt IRcvNotice) + type PacketToStr func(IRcvPkt) string + type PktToKey func(pkt IRcvPkt) string + type TCode = uint8 + type TLevel = int64 + const TDebug + const TError + const TFatal + const TInfo + const TWarn + func LvlToMask(levels ...int64) TLevel + func StrLvlToMask(levels ...string) TLevel + func StrToLevel(l string) TLevel + type TSvc = uint16 + type TSvcCode = uint16 + func MergeSvcCode(svc TSvc, code TCode) TSvcCode + type Var interface + type WorkerFn func(id string, fn util.FnAnySlc, params ...any)