Versions in this module Expand all Collapse all v1 v1.0.1 Apr 22, 2024 Changes in this version type Context + func (ctx *Context) SvrNeedSendHB(timeout time.Duration) bool type TcpX + ClientHBOn bool + ClientHBTimeout time.Duration + HBMessageID int32 + HBToClientFunc func(c *Context) + HBToClientOn bool + HBToClientTimeout time.Duration + func (tcpx *TcpX) ClientHBMode(chkCliHBOn bool, cliHBTimeout time.Duration) *TcpX + func (tcpx *TcpX) ClientHBModeDetail(chkCliHBOn bool, cliHBTimeout time.Duration, throughMiddleware bool, ...) *TcpX + func (tcpx *TcpX) HBToClientMode(sendHBOn bool, sendHBTimeout time.Duration, f func(c *Context)) + func (tcpx *TcpX) RewriteClientHBHandler(messageID int32, f func(c *Context)) *TcpX v1.0.0 Apr 19, 2024 Changes in this version + const ABORT + const CLIENT_ERROR + const CONTEXT_OFFLINE + const CONTEXT_ONLINE + const DEBUG + const DEFAULT_AUTH_MESSAGEID + const DEFAULT_HEARTBEAT_MESSAGEID + const MESSAGEID + const NOT_AUTH + const NOT_EXPIRE + const OK + const PIPED + const RELEASE + const SERVER_ERROR + const STATE_RUNNING + const STATE_STOP + const URLPATTERN + var B = 1 + var GB = 1024 * 1024 * 1024 + var HEADER_PACK_TYPE = "Pack-Content-Type" + var HEADER_ROUTER_KEY = "Router-Type" + var HEADER_ROUTER_VALUE = "Router-Pattern-Value" + var KB = 1024 + var Logger = Log + var MB = 1024 * 1024 + var PackJSON = NewPackx(JsonMarshaller{}) + var PackProtobuf = NewPackx(ProtobufMarshaller{}) + var PackTOML = NewPackx(TomlMarshaller{}) + var PackXML = NewPackx(XmlMarshaller{}) + var PackYAML = NewPackx(YamlMarshaller{}) + func BindJSON(bodyBuf []byte, dest interface{}) error + func BodyBytesOf(stream []byte) ([]byte, error) + func BodyLengthOf(stream []byte) (int32, error) + func CloseChanel(f func()) + func Debug(src interface{}) string + func Defer(f func(), handlePanicError ...func(interface{})) + func FirstBlockOf(r io.Reader) ([]byte, error) + func FirstBlockOfBytes(buffer []byte) ([]byte, error) + func FirstBlockOfLimitMaxByte(r io.Reader, maxByte int32) ([]byte, error) + func HeaderBytesOf(stream []byte) ([]byte, error) + func HeaderLengthOf(stream []byte) (int32, error) + func HeaderOf(stream []byte) (map[string]interface{}, error) + func In(s string, arr []string) bool + func LengthOf(stream []byte) (int32, error) + func MD5(rawMsg string) string + func MarshalTOML(src interface{}) ([]byte, error) + func MessageIDOf(stream []byte) (int32, error) + func Pack(messageID int32, header map[string]interface{}, src interface{}, ...) ([]byte, error) + func PackHeartbeat() []byte + func PackStuff(messageID int32) []byte + func PackWithMarshaller(message Message, marshaller Marshaller) ([]byte, error) + func PackWithMarshallerAndBody(message Message, body []byte) ([]byte, error) + func PackWithMarshallerName(message Message, marshallerName string) ([]byte, error) + func PipeJSON(conn net.Conn, args ...interface{}) error + func ReadAllUDP(conn net.PacketConn, maxBufferSize ...int) ([]byte, net.Addr, error) + func RouteTypeOf(stream []byte) (string, error) + func SetLogFlags(flags int) + func SetLogMode(mode int) + func TCPCallOnceJSON(network string, url string, messageID int, data interface{}) error + func TCPConnect(network string, url string) (net.Conn, error) + func URLPatternOf(stream []byte) (string, error) + func UnPackFromReader(r io.Reader) (int32, map[string]interface{}, []byte, error) + func UnmarshalTOML(buf []byte, dest interface{}) error + func UnpackToBlockFromReader(reader io.Reader) ([]byte, error) + func UnpackToBlockFromReaderLimitMaxLengthOfByte(reader io.Reader, maxByTe int) ([]byte, error) + func WriteConn(buf []byte, conn net.Conn) error + func WriteJSON(conn net.Conn, messageID int32, src interface{}) error + type AnchorMiddlewareInfo struct + WhereUnUse []string + WhereUse []string + type ClientPool struct + Clients map[string]*Context + var GlobalClientPool *ClientPool + func NewClientPool() *ClientPool + func (cp *ClientPool) DeleteFromClientPool(username string) + func (cp *ClientPool) GetClientPool(username string) *Context + func (cp *ClientPool) Offline(username string) + func (cp *ClientPool) Online(username string, ctx *Context) + func (cp *ClientPool) SetClientPool(username string, ctx *Context) + type ConnEx struct + func NewConnEx(conn net.Conn) *ConnEx + func (c *ConnEx) GetData() interface{} + func (c *ConnEx) SetData(data interface{}) + type Context struct + Addr net.Addr + Conn net.Conn + ConnReader io.Reader + ConnWriter io.Writer + L *sync.RWMutex + PacketConn net.PacketConn + Packx *Packx + PerConnectionContext *sync.Map + PerRequestContext *sync.Map + Stream []byte + func NewContext(conn net.Conn, marshaller Marshaller) *Context + func NewTCPContext(conn net.Conn, marshaller Marshaller) *Context + func NewUDPContext(conn net.PacketConn, addr net.Addr, marshaller Marshaller) *Context + func (ctx *Context) Abort() + func (ctx *Context) AuthChan() <-chan int + func (ctx *Context) Bind(dest interface{}) (Message, error) + func (ctx *Context) BindWithMarshaller(dest interface{}, marshaller Marshaller) (Message, error) + func (ctx *Context) CloseConn() error + func (ctx *Context) ConnectionProtocolType() string + func (ctx *Context) GetCtxPerConn(k interface{}) (interface{}, bool) + func (ctx *Context) GetCtxPerRequest(k interface{}) (interface{}, bool) + func (ctx *Context) GetPoolRef() *ClientPool + func (ctx *Context) GetURLPattern() (string, error) + func (ctx *Context) GetUsername() string + func (ctx *Context) HeartBeatChan() chan int + func (ctx *Context) InitReaderAndWriter() error + func (ctx *Context) IsCliOnline(timeout time.Duration) bool + func (ctx *Context) IsOffline() bool + func (ctx *Context) IsOnline() bool + func (ctx *Context) JSON(messageID int32, src interface{}, headers ...map[string]interface{}) error + func (ctx *Context) JSONURLPattern(src interface{}) error + func (ctx *Context) Next() + func (ctx *Context) Offline() error + func (ctx *Context) Online(username string) error + func (ctx *Context) ProtoBuf(messageID int32, src interface{}, headers ...map[string]interface{}) error + func (ctx *Context) ProtobufURLPattern(src interface{}) error + func (ctx *Context) RawStream() ([]byte, error) + func (ctx *Context) RecvAuthDeny() + func (ctx *Context) RecvAuthPass() + func (ctx *Context) RecvHeartBeat() + func (ctx *Context) Reply(messageID int32, src interface{}, headers ...map[string]interface{}) error + func (ctx *Context) ReplyWithMarshaller(marshaller Marshaller, messageID int32, src interface{}, ...) error + func (ctx *Context) Reset() + func (ctx *Context) ResetOffset() + func (ctx *Context) SendToConn(anotherCtx *Context, messageID int32, src interface{}, ...) error + func (ctx *Context) SendToUsername(username string, messageID int32, src interface{}, ...) error + func (ctx *Context) SetCtxPerConn(k, v interface{}) + func (ctx *Context) SetCtxPerRequest(k, v interface{}) + func (ctx *Context) SetDeadline(t time.Time) error + func (ctx *Context) SetReadDeadline(t time.Time) error + func (ctx *Context) SetUsername(username string) + func (ctx *Context) SetWriteDeadline(t time.Time) error + func (ctx *Context) SvrNeedSendHeartbeat(timeout time.Duration) bool + func (ctx *Context) TOML(messageID int32, src interface{}, headers ...map[string]interface{}) error + func (ctx *Context) UpdateCliActiveTime() + func (ctx *Context) UpdateLatestSendTime() + func (ctx *Context) Username() (string, bool) + func (ctx *Context) XML(messageID int32, src interface{}, headers ...map[string]interface{}) error + func (ctx *Context) YAML(messageID int32, src interface{}, headers ...map[string]interface{}) error + func (ctx Context) ClientIP() string + func (ctx Context) Network() string + func (ctx Context) RouterType() string + type H map[string]interface + type JsonMarshaller struct + func (js JsonMarshaller) Marshal(v interface{}) ([]byte, error) + func (js JsonMarshaller) MarshalName() string + func (js JsonMarshaller) Unmarshal(data []byte, dest interface{}) error + type Log struct + Logger *log.Logger + Mode int + func (l *Log) SetLogFlags(flags int) + func (l *Log) SetLogMode(mode int) + func (l Log) Println(info ...interface{}) + type Marshaller interface + Marshal func(interface{}) ([]byte, error) + MarshalName func() string + Unmarshal func([]byte, interface{}) error + func GetMarshallerByMarshalName(marshalName string) (Marshaller, error) + type Message struct + Body interface{} + Header map[string]interface{} + MessageID int32 + func NewMessage(messageID int32, src interface{}) Message + func NewURLPatternMessage(urlPattern string, src interface{}) Message + func UnpackWithMarshaller(stream []byte, dest interface{}, marshaller Marshaller) (Message, error) + func UnpackWithMarshallerName(stream []byte, dest interface{}, marshallerName string) (Message, error) + func (m Message) Pack(marshaller Marshaller) ([]byte, error) + func (msg *Message) Set(k string, v interface{}) + func (msg Message) Get(key string) interface{} + type MessageIDAnchor struct + AnchorIndex int + MessageID int32 + URLPattern string + func NewMessageIDAnchor(messageID int32, anchorIndex int) MessageIDAnchor + func NewUrlPatternAnchor(urlPattern string, anchorIndex int) MessageIDAnchor + type MiddlewareAnchor struct + AnchorEndIndexRange []int + AnchorStartIndexRange []int + Middleware func(c *Context) + MiddlewareKey string + func (ma *MiddlewareAnchor) Contains(handlerIndex int) bool + func (ma *MiddlewareAnchor) FormatPath() string + type Mux struct + AllowAdd bool + GlobalMiddlewares []func(ctx *Context) + Handlers map[int32]func(ctx *Context) + MessageIDAnchorMap map[int32]MessageIDAnchor + MessageIDSelfMiddleware map[int32][]func(ctx *Context) + MiddlewareAnchorMap map[string]MiddlewareAnchor + MiddlewareAnchors []MiddlewareAnchor + Mutex *sync.RWMutex + func NewMux() *Mux + func (mux *Mux) AddGlobalMiddleware(handlers ...func(c *Context)) + func (mux *Mux) AddHandleFunc(messageID int32, handler func(ctx *Context)) + func (mux *Mux) AddMessageIDAnchor(anchor MessageIDAnchor) + func (mux *Mux) AddMessageIDSelfMiddleware(messageID int32, handlers ...func(c *Context)) + func (mux *Mux) AddMiddlewareAnchor(anchor MiddlewareAnchor) + func (mux *Mux) AddURLAnchor(anchor MessageIDAnchor) + func (mux *Mux) AnchorIndexOfMessageID(messageID int32) int + func (mux *Mux) AnchorIndexOfURLPattern(urlPattern string) int + func (mux *Mux) Any(urlPattern string, handlers ...func(c *Context)) error + func (mux *Mux) CurrentAnchorIndex() int + func (mux *Mux) ReplaceMiddlewareAnchor(anchor MiddlewareAnchor) + type PackType []byte + func Recv(conn net.Conn) (PackType, error) + func (pt *PackType) BindJSON(dest interface{}) error + func (pt *PackType) BindProtobuf(dest proto.Message) error + func (pt *PackType) BindTOML(dest interface{}) error + func (pt *PackType) BindXML(dest interface{}) error + func (pt *PackType) BindYAML(dest interface{}) error + func (pt *PackType) MessageID() (int32, error) + func (pt *PackType) URLPattern() (string, error) + type Packx struct + Marshaller Marshaller + func NewPackx(marshaller Marshaller) *Packx + func (packx Packx) BodyBytesOf(stream []byte) ([]byte, error) + func (packx Packx) BodyLengthOf(stream []byte) (int32, error) + func (packx Packx) FirstBlockOf(r io.Reader) ([]byte, error) + func (packx Packx) FirstBlockOfBytes(buffer []byte) ([]byte, error) + func (packx Packx) FirstBlockOfLimitMaxByte(r io.Reader, maxByte int32) ([]byte, error) + func (packx Packx) HeaderBytesOf(stream []byte) ([]byte, error) + func (packx Packx) HeaderLengthOf(stream []byte) (int32, error) + func (packx Packx) HeaderOf(stream []byte) (map[string]interface{}, error) + func (packx Packx) LengthOf(stream []byte) (int32, error) + func (packx Packx) MessageIDOf(stream []byte) (int32, error) + func (packx Packx) Pack(messageID int32, src interface{}, headers ...map[string]interface{}) ([]byte, error) + func (packx Packx) PackWithBody(messageID int32, body []byte, headers ...map[string]interface{}) ([]byte, error) + func (packx Packx) Unpack(stream []byte, dest interface{}) (Message, error) + type PropertyCache struct + Listener interface{} + Network string + Port string + type ProtobufMarshaller struct + func (pm ProtobufMarshaller) Marshal(v interface{}) ([]byte, error) + func (pm ProtobufMarshaller) MarshalName() string + func (pm ProtobufMarshaller) Unmarshal(data []byte, dest interface{}) error + type Request struct + Body io.ReadCloser + Header map[string]interface{} + URL string + func NewRequest(url string, reader io.Reader) *Request + func (r *Request) Set(key string, value interface{}) + type Route struct + MessageId int + URLPattern string + Whereis []string + func (r *Route) Merge(r2 Route) Route + func (r Route) Location() string + type TcpX struct + AuthMessageID int32 + AuthThroughMiddleware bool + CheckCliHeartBeatOn bool + CliHeatBeatTimeout time.Duration + HandleRaw func(c *Context) + HeartBeatMessageID int32 + HeatBeatToCliInterval time.Duration + Mux *Mux + OnClose func(ctx *Context) + OnConnect func(ctx *Context) + OnHeartbeatLoss func(c *Context) + OnMessage func(ctx *Context) + Packx *Packx + SendHeartbeatToCliOn bool + TLSConfig *tls.Config + ThroughMiddleware bool + func NewTcpX(marshaller Marshaller) *TcpX + func (tcpx *TcpX) AddHandler(messageID int32, handlers ...func(ctx *Context)) + func (tcpx *TcpX) Any(urlPattern string, handlers ...func(ctx *Context)) + func (tcpx *TcpX) BeforeExit(f ...func()) + func (tcpx *TcpX) HeartBeatMode(chkCliHBOn bool, cliHBTimeout time.Duration, sendHBOn bool, ...) *TcpX + func (tcpx *TcpX) HeartBeatModeDetail(chkCliHBOn bool, cliHBTimeout time.Duration, sendHBOn bool, ...) *TcpX + func (tcpx *TcpX) ListenAndServe(network, addr string) error + func (tcpx *TcpX) ListenAndServeGRPC(network, addr string) error + func (tcpx *TcpX) ListenAndServeHTTP(network, addr string) error + func (tcpx *TcpX) ListenAndServeRaw(network, addr string) error + func (tcpx *TcpX) ListenAndServeTCP(network, addr string) error + func (tcpx *TcpX) ListenAndServeUDP(network, addr string, maxBufferSize ...int) error + func (tcpx *TcpX) LoadTLSFile(certPath string, keyPath string) error + func (tcpx *TcpX) Restart(closeAllConnection bool, beforeStart ...func()) error + func (tcpx *TcpX) RewriteHeartBeatHandler(messageID int32, f func(c *Context)) *TcpX + func (tcpx *TcpX) SetDeadline(t time.Time) + func (tcpx *TcpX) SetEventOnHeartbeatLoss(f func(c *Context)) + func (tcpx *TcpX) SetMaxBytePerMessage(maxByte int32) + func (tcpx *TcpX) SetReadDeadline(t time.Time) + func (tcpx *TcpX) SetWriteDeadline(t time.Time) + func (tcpx *TcpX) Start() error + func (tcpx *TcpX) State() int + func (tcpx *TcpX) Stop(closeAllConnection bool) error + func (tcpx *TcpX) UnUse(middlewareKeys ...string) + func (tcpx *TcpX) Use(mids ...interface{}) + func (tcpx *TcpX) UseGlobal(mids ...func(c *Context)) + func (tcpx *TcpX) WithAuthDetail(yes bool, duration time.Duration, throughMiddleware bool, messageID int32, ...) *TcpX + func (tcpx *TcpX) WithBroadCastSignal(yes bool) *TcpX + func (tcpx *TcpX) WithBuiltInPool(yes bool) *TcpX + type TomlMarshaller struct + func (tm TomlMarshaller) Marshal(v interface{}) ([]byte, error) + func (tm TomlMarshaller) MarshalName() string + func (tm TomlMarshaller) Unmarshal(data []byte, dest interface{}) error + type URLMux struct + URLAnchorMap map[string]MessageIDAnchor + func NewURLMux() *URLMux + func (m *URLMux) AddURLPatternHandler(urlPattern string, handlers ...func(c *Context)) error + func (m *URLMux) LockWrite() + func (m *URLMux) PanicOnExistRouter() error + type XmlMarshaller struct + func (xm XmlMarshaller) Marshal(v interface{}) ([]byte, error) + func (xm XmlMarshaller) MarshalName() string + func (xm XmlMarshaller) Unmarshal(data []byte, dest interface{}) error + type YamlMarshaller struct + func (ym YamlMarshaller) Marshal(v interface{}) ([]byte, error) + func (ym YamlMarshaller) MarshalName() string + func (ym YamlMarshaller) Unmarshal(data []byte, dest interface{}) error