core

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HdHeartbeat uint8 = iota + 1
	HdPush
	HdRequest
	HdOk
	HdFail
	HdWatch
	HdNotify
)
View Source
const (
	HeadId    = "id"
	HeadSvc   = "svc"
	HeadCode  = "cod"
	HeadSndId = "snd_id"
	HeadSndTs = "snd_ts"
)
View Source
const (
	DefConnCap = 1 << 12
)

Variables

View Source
var (
	MaxReconnect = 5
	MaxSendRetry = uint8(3)
	SendRetryDur = time.Second
)
View Source
var (
	GenHead util.FnM = func(m util.M) {

	}
)
View Source
var (
	Heartbeat = []byte{HdHeartbeat}
)
View Source
var (
	ResponseTimeoutDur = time.Duration(5000) * time.Millisecond
)

Functions

func ActivePrcNtc

func ActivePrcNtc[Ntc util.IMsg](pkt kiwi.IRcvNotice, key string, handler func(kiwi.IRcvNotice, Ntc))

func ActivePrcPus

func ActivePrcPus[Pus util.IMsg](pkt kiwi.IRcvPush, key string, handler func(kiwi.IRcvPush, Pus))

func ActivePrcReq

func ActivePrcReq[Req, Res util.IMsg](pkt kiwi.IRcvRequest, key string, handler func(kiwi.IRcvRequest, Req, Res))

func AsyncReq

func AsyncReq(pid int64, head util.M, msg util.IMsg, onFail util.FnInt64MUint16, onOk util.FnInt64MMsg)

func AsyncReqBytes

func AsyncReqBytes(pid int64, svc kiwi.TSvc, code kiwi.TCode, head util.M, json bool, payload []byte,
	onFail util.FnInt64MUint16, onOk util.FnInt64MBytes)

func AsyncReqNode

func AsyncReqNode(pid, nodeId int64, head util.M, msg util.IMsg, onFail util.FnInt64MUint16, onOk util.FnInt64MMsg)

func AsyncReqNodeBytes

func AsyncReqNodeBytes(pid, nodeId int64, svc kiwi.TSvc, code kiwi.TCode, head util.M, json bool, payload []byte,
	onFail util.FnInt64MUint16, onOk util.FnInt64MBytes)

func AsyncSubReq

func AsyncSubReq[ResT util.IMsg](pkt kiwi.IRcvRequest, head util.M, req util.IMsg, resFail util.FnInt64MUint16, resOk func(int64, util.M, ResT))

func BindMsgToSvcCode

func BindMsgToSvcCode(msg util.IMsg, svc kiwi.TSvc, code kiwi.TCode)

func CompletePktCount

func CompletePktCount() uint64

func ExcludeLog

func ExcludeLog(svc kiwi.TSvc, codes ...kiwi.TCode)

func GetService

func GetService(svc kiwi.TSvc) (kiwi.IService, bool)

func GlobalPrcNtc

func GlobalPrcNtc[Ntc util.IMsg](pkt kiwi.IRcvNotice, handler func(kiwi.IRcvNotice, Ntc))

func GlobalPrcPus

func GlobalPrcPus[Pus util.IMsg](pkt kiwi.IRcvPush, handler func(kiwi.IRcvPush, Pus))

func GlobalPrcReq

func GlobalPrcReq[Req, Res util.IMsg](pkt kiwi.IRcvRequest, handler func(kiwi.IRcvRequest, Req, Res))

func GoPrcNtc

func GoPrcNtc[Ntc util.IMsg](pkt kiwi.IRcvNotice, handler func(kiwi.IRcvNotice, Ntc))

func GoPrcPus

func GoPrcPus[Pus util.IMsg](pkt kiwi.IRcvPush, handler func(kiwi.IRcvPush, Pus))

func GoPrcReq

func GoPrcReq[Req, Res util.IMsg](pkt kiwi.IRcvRequest, handler func(kiwi.IRcvRequest, Req, Res))

func InitCodec

func InitCodec()

func InitGate

func InitGate(receiver kiwi.FnAgentBytes, opts ...GateOption)

func InitNodeLocal

func InitNodeLocal()

func InitNodeNet

func InitNodeNet(opts ...NodeOption)

func InitNodeTest

func InitNodeTest()

func InitPacker

func InitPacker()

func InitRouter

func InitRouter()

func IsExcludeLog

func IsExcludeLog(svc kiwi.TSvc, code kiwi.TCode) bool

func MsgToSvcCode

func MsgToSvcCode(msg util.IMsg) (svc kiwi.TSvc, code kiwi.TCode, ok bool)

func NewNodeLocal

func NewNodeLocal() kiwi.INode

func NewNodeNet

func NewNodeNet(opts ...NodeOption) kiwi.INode

func Ntf

func Ntf(pid int64, head util.M, msg util.IMsg) int64

func Pus

func Pus(pid int64, head util.M, msg util.IMsg) int64

func PusNode

func PusNode(pid, nodeId int64, head util.M, msg util.IMsg) int64

func ReceivePktCount

func ReceivePktCount() uint64

func RegisterSvc

func RegisterSvc(services ...kiwi.IService)

func Req

func Req[ResT util.IMsg](pid int64, head util.M, msg util.IMsg) (ResT, util.M, uint16)

func Req2

func Req2(pid int64, head util.M, msg util.IMsg) (util.IMsg, util.M, uint16)

func ReqBytes

func ReqBytes(pid int64, svc kiwi.TSvc, code kiwi.TCode, head util.M, json bool, payload []byte) ([]byte, util.M, uint16)

func ReqNode

func ReqNode[ResT any](nodeId, pid int64, head util.M, msg util.IMsg) (ResT, util.M, uint16)

func ReqNodeBytes

func ReqNodeBytes(nodeId, pid int64, svc kiwi.TSvc, code kiwi.TCode, head util.M, json bool, payload []byte) ([]byte, util.M, uint16)

func ResponseSendFailCount

func ResponseSendFailCount() uint64

func SelfPrcNtc

func SelfPrcNtc[Ntc util.IMsg](pkt kiwi.IRcvNotice, handler func(kiwi.IRcvNotice, Ntc))

func SelfPrcPus

func SelfPrcPus[Pus util.IMsg](pkt kiwi.IRcvPush, handler func(kiwi.IRcvPush, Pus))

func SelfPrcReq

func SelfPrcReq[Req, Res util.IMsg](pkt kiwi.IRcvRequest, handler func(kiwi.IRcvRequest, Req, Res))

func SharePrcNtc

func SharePrcNtc[Ntc util.IMsg](pkt kiwi.IRcvNotice, key string, handler func(kiwi.IRcvNotice, Ntc))

func SharePrcPus

func SharePrcPus[Pus util.IMsg](pkt kiwi.IRcvPush, key string, handler func(kiwi.IRcvPush, Pus))

func SharePrcReq

func SharePrcReq[Req, Res util.IMsg](pkt kiwi.IRcvRequest, key string, handler func(kiwi.IRcvRequest, Req, Res))

func ShutdownAllService

func ShutdownAllService()

func StartAllService

func StartAllService()

func StartDefault

func StartDefault(opts ...Option)

Types

type Gate

type Gate struct {
	// contains filtered or unexported fields
}

type GateOption

type GateOption func(option *gateOption)

func GateCheckIp

func GateCheckIp(fn util.StrToBool) GateOption

func GateConnCap

func GateConnCap(cap int32) GateOption

func GateConnected

func GateConnected(connected kiwi.FnAgent) GateOption

func GateDeadlineSecs

func GateDeadlineSecs(deadline int) GateOption

func GateDisconnected

func GateDisconnected(disconnected kiwi.FnAgentErr) GateOption

func GateHeadLen

func GateHeadLen(headLen uint32) GateOption

func GateIp

func GateIp(ip string) GateOption

func GateRoles

func GateRoles(roles map[kiwi.TSvcCode][]int64) GateOption

func GateTcpPort

func GateTcpPort(port int) GateOption

func GateUdpPort

func GateUdpPort(port int) GateOption

func GateWebsocketPort

func GateWebsocketPort(port int) GateOption

type Meta

type Meta struct {
	Id          int64
	SvcToVer    map[string]string
	SvcNameConv func(string) kiwi.TSvc
}

type Mongo

type Mongo struct {
	// contains filtered or unexported fields
}

type NodeConnType

type NodeConnType uint8
const (
	Tcp NodeConnType = iota
	Udp
)

type NodeDialerSelector

type NodeDialerSelector func(set *ds.Set2Item[kiwi.TSvc, int64, kiwi.INodeDialer]) (int64, *util.Err)

type NodeOption

type NodeOption func(opt *nodeOption)

func NodeIp

func NodeIp(ip string) NodeOption

func NodePort

func NodePort(port int) NodeOption

func NodeSelector

func NodeSelector(selector NodeDialerSelector) NodeOption

func NodeType

func NodeType(t NodeConnType) NodeOption

type OnNetDialerConnected

type OnNetDialerConnected func(*nodeDialer)

type OnNetDialerDisconnected

type OnNetDialerDisconnected func(*nodeDialer, *util.Err)

type Option

type Option func(*option)

func SetGate

func SetGate(receiver kiwi.FnAgentBytes, options ...GateOption) Option

func SetLoggers

func SetLoggers(loggers ...kiwi.ILogger) Option

func SetMeta

func SetMeta(meta *Meta) Option

func SetMongoDB

func SetMongoDB(uri, db string, options *options.DatabaseOptions) Option

func SetRedis

func SetRedis(addr, user, pw string, db int) Option

func SetServices

func SetServices(services []kiwi.IService) Option

func SetWorker

func SetWorker(active, share, parallel, global bool) Option

type RcvNtfPkt

type RcvNtfPkt struct {
	// contains filtered or unexported fields
}

func NewRcvNtfPkt

func NewRcvNtfPkt() *RcvNtfPkt

func (*RcvNtfPkt) Code

func (p *RcvNtfPkt) Code() kiwi.TCode

func (*RcvNtfPkt) Complete

func (p *RcvNtfPkt) Complete()

func (*RcvNtfPkt) Err

func (p *RcvNtfPkt) Err(err *util.Err)

func (*RcvNtfPkt) Err2

func (p *RcvNtfPkt) Err2(code util.TErrCode, m util.M)

func (*RcvNtfPkt) Err3

func (p *RcvNtfPkt) Err3(code util.TErrCode, e error)

func (*RcvNtfPkt) Head

func (p *RcvNtfPkt) Head() util.M

func (*RcvNtfPkt) HeadId

func (p *RcvNtfPkt) HeadId() string

func (*RcvNtfPkt) InitWithBytes

func (p *RcvNtfPkt) InitWithBytes(msgType uint8, tid int64, head util.M, json bool, payload []byte) *util.Err

func (*RcvNtfPkt) InitWithMsg

func (p *RcvNtfPkt) InitWithMsg(msgType uint8, tid int64, head util.M, json bool, msg util.IMsg)

func (*RcvNtfPkt) Json

func (p *RcvNtfPkt) Json() bool

func (*RcvNtfPkt) Msg

func (p *RcvNtfPkt) Msg() util.IMsg

func (*RcvNtfPkt) SenderId

func (p *RcvNtfPkt) SenderId() int64

func (*RcvNtfPkt) SetWorker

func (p *RcvNtfPkt) SetWorker(typ kiwi.EWorker, key string)

func (*RcvNtfPkt) Svc

func (p *RcvNtfPkt) Svc() kiwi.TSvc

func (*RcvNtfPkt) Tid

func (p *RcvNtfPkt) Tid() int64

func (*RcvNtfPkt) Worker

func (p *RcvNtfPkt) Worker() kiwi.EWorker

func (*RcvNtfPkt) WorkerKey

func (p *RcvNtfPkt) WorkerKey() string

type RcvPusPkt

type RcvPusPkt struct {
	// contains filtered or unexported fields
}

func NewRcvPusPkt

func NewRcvPusPkt() *RcvPusPkt

func (*RcvPusPkt) Code

func (p *RcvPusPkt) Code() kiwi.TCode

func (*RcvPusPkt) Complete

func (p *RcvPusPkt) Complete()

func (*RcvPusPkt) Err

func (p *RcvPusPkt) Err(err *util.Err)

func (*RcvPusPkt) Err2

func (p *RcvPusPkt) Err2(code util.TErrCode, m util.M)

func (*RcvPusPkt) Err3

func (p *RcvPusPkt) Err3(code util.TErrCode, e error)

func (*RcvPusPkt) Head

func (p *RcvPusPkt) Head() util.M

func (*RcvPusPkt) HeadId

func (p *RcvPusPkt) HeadId() string

func (*RcvPusPkt) InitWithBytes

func (p *RcvPusPkt) InitWithBytes(msgType uint8, tid int64, head util.M, json bool, payload []byte) *util.Err

func (*RcvPusPkt) InitWithMsg

func (p *RcvPusPkt) InitWithMsg(msgType uint8, tid int64, head util.M, json bool, msg util.IMsg)

func (*RcvPusPkt) Json

func (p *RcvPusPkt) Json() bool

func (*RcvPusPkt) Msg

func (p *RcvPusPkt) Msg() util.IMsg

func (*RcvPusPkt) SenderId

func (p *RcvPusPkt) SenderId() int64

func (*RcvPusPkt) SetWorker

func (p *RcvPusPkt) SetWorker(typ kiwi.EWorker, key string)

func (*RcvPusPkt) Svc

func (p *RcvPusPkt) Svc() kiwi.TSvc

func (*RcvPusPkt) Tid

func (p *RcvPusPkt) Tid() int64

func (*RcvPusPkt) Worker

func (p *RcvPusPkt) Worker() kiwi.EWorker

func (*RcvPusPkt) WorkerKey

func (p *RcvPusPkt) WorkerKey() string

type RcvReqPkt

type RcvReqPkt struct {
	// contains filtered or unexported fields
}

func NewRcvReqPkt

func NewRcvReqPkt() *RcvReqPkt

func (*RcvReqPkt) Code

func (p *RcvReqPkt) Code() kiwi.TCode

func (*RcvReqPkt) Complete

func (p *RcvReqPkt) Complete()

func (*RcvReqPkt) Err

func (p *RcvReqPkt) Err(err *util.Err)

func (*RcvReqPkt) Err2

func (p *RcvReqPkt) Err2(code util.TErrCode, m util.M)

func (*RcvReqPkt) Err3

func (p *RcvReqPkt) Err3(code util.TErrCode, e error)

func (*RcvReqPkt) Fail

func (p *RcvReqPkt) Fail(code uint16)

func (*RcvReqPkt) Head

func (p *RcvReqPkt) Head() util.M

func (*RcvReqPkt) HeadId

func (p *RcvReqPkt) HeadId() string

func (*RcvReqPkt) InitWithBytes

func (p *RcvReqPkt) InitWithBytes(msgType uint8, tid int64, head util.M, json bool, payload []byte) *util.Err

func (*RcvReqPkt) InitWithMsg

func (p *RcvReqPkt) InitWithMsg(msgType uint8, tid int64, head util.M, json bool, msg util.IMsg)

func (*RcvReqPkt) Json

func (p *RcvReqPkt) Json() bool

func (*RcvReqPkt) Msg

func (p *RcvReqPkt) Msg() util.IMsg

func (*RcvReqPkt) Ok

func (p *RcvReqPkt) Ok(msg util.IMsg)

func (*RcvReqPkt) SenderId

func (p *RcvReqPkt) SenderId() int64

func (*RcvReqPkt) SetWorker

func (p *RcvReqPkt) SetWorker(typ kiwi.EWorker, key string)

func (*RcvReqPkt) Svc

func (p *RcvReqPkt) Svc() kiwi.TSvc

func (*RcvReqPkt) Tid

func (p *RcvReqPkt) Tid() int64

func (*RcvReqPkt) Worker

func (p *RcvReqPkt) Worker() kiwi.EWorker

func (*RcvReqPkt) WorkerKey

func (p *RcvReqPkt) WorkerKey() string

type Redis

type Redis struct {
	Addr     string
	User     string
	Password string
	Db       int
}

type SNotify

type SNotify struct {
	// contains filtered or unexported fields
}

func (*SNotify) Code

func (p *SNotify) Code() kiwi.TCode

func (*SNotify) Dispose

func (n *SNotify) Dispose()

func (*SNotify) GetSvcNodeId

func (p *SNotify) GetSvcNodeId() (int64, bool)

func (*SNotify) Head

func (p *SNotify) Head() util.M

func (*SNotify) InitHead

func (p *SNotify) InitHead()

func (*SNotify) Json

func (p *SNotify) Json() bool

func (*SNotify) Msg

func (p *SNotify) Msg() util.IMsg

func (*SNotify) Payload

func (p *SNotify) Payload() []byte

func (*SNotify) Pid

func (p *SNotify) Pid() int64

func (*SNotify) Svc

func (p *SNotify) Svc() kiwi.TSvc

func (*SNotify) Tid

func (p *SNotify) Tid() int64

type SPush

type SPush struct {
	// contains filtered or unexported fields
}

func (*SPush) Code

func (p *SPush) Code() kiwi.TCode

func (*SPush) Dispose

func (p *SPush) Dispose()

func (*SPush) GetSvcNodeId

func (p *SPush) GetSvcNodeId() (int64, bool)

func (*SPush) Head

func (p *SPush) Head() util.M

func (*SPush) InitHead

func (p *SPush) InitHead()

func (*SPush) Json

func (p *SPush) Json() bool

func (*SPush) Msg

func (p *SPush) Msg() util.IMsg

func (*SPush) Payload

func (p *SPush) Payload() []byte

func (*SPush) Pid

func (p *SPush) Pid() int64

func (*SPush) Svc

func (p *SPush) Svc() kiwi.TSvc

func (*SPush) Tid

func (p *SPush) Tid() int64

type SRequest

type SRequest struct {
	// contains filtered or unexported fields
}

func (*SRequest) Code

func (p *SRequest) Code() kiwi.TCode

func (*SRequest) Dispose

func (r *SRequest) Dispose()

func (*SRequest) Fail

func (r *SRequest) Fail(head util.M, code uint16)

func (*SRequest) GetSvcNodeId

func (p *SRequest) GetSvcNodeId() (int64, bool)

func (*SRequest) Head

func (p *SRequest) Head() util.M

func (*SRequest) InitHead

func (p *SRequest) InitHead()

func (*SRequest) Json

func (p *SRequest) Json() bool

func (*SRequest) Msg

func (p *SRequest) Msg() util.IMsg

func (*SRequest) Ok

func (r *SRequest) Ok(head util.M, msg util.IMsg)

func (*SRequest) OkBytes

func (r *SRequest) OkBytes(head util.M, bytes []byte)

func (*SRequest) Payload

func (p *SRequest) Payload() []byte

func (*SRequest) Pid

func (p *SRequest) Pid() int64

func (*SRequest) SetBytesHandler

func (r *SRequest) SetBytesHandler(fail util.FnInt64MUint16, ok util.FnInt64MBytes)

func (*SRequest) SetHandler

func (r *SRequest) SetHandler(fail util.FnInt64MUint16, ok util.FnInt64MMsg)

func (*SRequest) Svc

func (p *SRequest) Svc() kiwi.TSvc

func (*SRequest) Tid

func (p *SRequest) Tid() int64

type Worker

type Worker struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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