Versions in this module Expand all Collapse all v0 v0.0.1 Oct 23, 2023 Changes in this version + const DefaultClientName + const DefaultConnectCode + const DefaultNoticeMaxRetry + const DefaultNoticeRetryTimer + const DefaultSGetTimeOut + const DefaultSecretKey + const DefaultServersName + const HeartbeatTime + const HeartbeatTimeLast + const ServersTimeWheel + const SignLetterBytes + var ErrClientNameErr = fmt.Errorf("client name 不能含特殊字符 @") + var ErrClientSecretKey = fmt.Errorf("秘钥的长度只能为8,并且与Servers端统一") + var ErrDataLengthAbove = fmt.Errorf("数据大于 540个字节, 建议拆分") + var ErrNmeLengthAbove = fmt.Errorf("名字不能超过7个长度") + var ErrNonePacket = fmt.Errorf("空包") + var ErrNotFondClient = func(name string) error + var ErrSGetTimeOut = func(label, name, ip string) error + var ErrServersSecretKey = fmt.Errorf("秘钥的长度只能为8,并且与Client端统一") + var GetDataMap sync.Map + var LevelMap = map[Level]string + var LogClose bool = true + var NoticeDataMap sync.Map + var PanicGetHandleFuncExist = func(label string) + var PanicPutHandleFuncExist = func(label string) + func BacklogLoad() + func ByteToObj(data []byte, obj interface{}) error + func CloseLog() + func DesECBDecrypt(data, key []byte) []byte + func DesECBEncrypt(data, key []byte) []byte + func Error(args ...interface{}) + func ErrorF(format string, args ...interface{}) + func GzipCompress(src []byte) []byte + func GzipDecompress(src []byte) ([]byte, error) + func ID64() (int64, error) + func Info(args ...interface{}) + func InfoF(format string, args ...interface{}) + func ObjToByte(obj interface{}) ([]byte, error) + func PacketEncoder(cmd CommandCode, name, sign, secret string, data []byte) ([]byte, error) + func SetLogFile(name string) + func SignCheck(addr, sign string) bool + func SignGet(addr string) string + func SignStore(addr, sign string) + func Version() string + func ZlibCompress(src []byte) []byte + func ZlibDecompress(src []byte) ([]byte, error) + type Client struct + Conn *net.UDPConn + GetHandle ClientGetFunc + NoticeHandle ClientNoticeFunc + SConn *net.UDPAddr + ServersHost string + func NewClient(host string, conf ...ClientConf) (*Client, error) + func (c *Client) Close() + func (c *Client) ConnectServers() + func (c *Client) DefaultClientName() + func (c *Client) DefaultConnectCode() + func (c *Client) DefaultSecretKey() + func (c *Client) Get(funcLabel string, param []byte) ([]byte, error) + func (c *Client) GetHandleFunc(label string, f func(c *Client, param []byte) (int, []byte)) + func (c *Client) GetName() string + func (c *Client) GetTimeOut(funcLabel string, param []byte, timeOut int) ([]byte, error) + func (c *Client) NoticeHandleFunc(label string, f func(c *Client, data []byte)) + func (c *Client) Put(funcLabel string, data []byte) + func (c *Client) ReplyGet(id int64, state int, data []byte) + func (c *Client) Run() + func (c *Client) SendBacklog() + func (c *Client) SetClientName(name string) error + func (c *Client) SetConnectCode(code string) + func (c *Client) SetSecretKey(key string) error + func (c *Client) Write(data []byte) + type ClientConf struct + ConnectCode string + Name string + SecretKey string + func SetClientConf(clientName, connectCode, secretKey string) ClientConf + type ClientConnInfo struct + Addr string + DiscardTime int64 + IP string + LastTime int64 + Name string + Online bool + type ClientConnectObj struct + Addr *net.UDPAddr + IP string + Last int64 + type ClientGetFunc map[string]func(c *Client, param []byte) (int, []byte) + type ClientInfo struct + Addr *net.UDPAddr + Interactive int64 + Name string + PacketSize int + type ClientNoticeFunc map[string]func(c *Client, data []byte) + type CommandCode uint8 + const CommandConnect + const CommandGet + const CommandHeartbeat + const CommandNotice + const CommandPut + const CommandReply + type GetData struct + Err error + Id int64 + Label string + Param []byte + Response []byte + type IdWorker struct + func (idw *IdWorker) InitIdWorker(workerId, datacenterId int64) error + func (idw *IdWorker) NextId() (int64, error) + type Level int + type NoticeData struct + Data []byte + Err error + Id int64 + Label string + Response []byte + type NoticeRetry struct + MaxRetry int + RetryTimer time.Duration + TimeOutTimer time.Duration + type Packet struct + Command CommandCode + Data []byte + Name string + Sign string + func PacketDecrypt(secret string, data []byte, n int) (*Packet, error) + type PutData struct + Body []byte + Id int64 + Label string + type Reply struct + CtxId int64 + Data []byte + StateCode int + Type int + type Servers struct + Addr string + CMap map[string]map[string]*ClientConnectObj + Conn *net.UDPConn + GetHandle ServersGetFunc + Port int + PutHandle ServersPutFunc + func NewServers(addr string, port int, conf ...ServersConf) (*Servers, error) + func (s *Servers) ClientDiscard(name, ip string) + func (s *Servers) DefaultConnectCode() + func (s *Servers) DefaultSecretKey() + func (s *Servers) DefaultServersName() + func (s *Servers) Get(funcLabel, name string, param []byte) ([]byte, error) + func (s *Servers) GetAtIP(funcLabel, name, ip string, param []byte) ([]byte, error) + func (s *Servers) GetAtIPTimeOut(timeOut int, funcLabel, name, ip string, param []byte) ([]byte, error) + func (s *Servers) GetAtNameTimeOut(timeOut int, funcLabel, name string, param []byte) ([]byte, error) + func (s *Servers) GetClientAllName() []string + func (s *Servers) GetClientConn(name string) (map[string]*ClientConnectObj, bool) + func (s *Servers) GetClientConnFromIP(name, ip string) (*net.UDPAddr, bool) + func (s *Servers) GetHandleFunc(label string, f func(s *Servers, param []byte) (int, []byte)) + func (s *Servers) GetServersName() string + func (s *Servers) Notice(name, label string, data []byte, retryConf *NoticeRetry) (string, error) + func (s *Servers) NoticeAll(label string, data []byte, retryConf *NoticeRetry) + func (s *Servers) OnLineTable() map[string]*ClientConnInfo + func (s *Servers) PutHandleFunc(label string, f func(s *Servers, c *ClientInfo, body []byte)) + func (s *Servers) ReplyGet(client *net.UDPAddr, id int64, state int, data []byte) + func (s *Servers) ReplyPut(client *net.UDPAddr, id, state int64) + func (s *Servers) Run() + func (s *Servers) SetConnectCode(code string) + func (s *Servers) SetNoticeRetry(maxRetry, retryTimer int) *NoticeRetry + func (s *Servers) SetSecretKey(key string) error + func (s *Servers) SetServersName(name string) error + func (s *Servers) Write(client *net.UDPAddr, data []byte) + type ServersConf struct + ConnectCode string + Name string + SecretKey string + func SetServersConf(serversName, connectCode, secretKey string) ServersConf + type ServersGetFunc map[string]func(s *Servers, param []byte) (int, []byte) + type ServersPutFunc map[string]func(s *Servers, c *ClientInfo, data []byte)