common

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2022 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TcpDealProtobuf uint32 = iota + 1
	TcpDealJson
)

tcp协议类型

View Source
const (
	PacketHeadLength int = 2
	TcpReadBufLen    int = 2048
)

packet常量

View Source
const (
	// 延迟时间
	DelayDuration time.Duration = time.Second
	// 服务注册时差
	TcpHeartDuration time.Duration = time.Duration(60) * time.Second
	// TCP请求超时市场
	TcpDeadDuration time.Duration = time.Duration(10) * time.Second
	// HTTP请求超时时间
	HttpDeadDuration time.Duration = time.Duration(30) * time.Second
	// 连接池
	TcpPoolIdMin int = 0
	TcpPoolIdMax int = 10
	// 获取对象最长等待时长 单位毫秒
	TcpPoolMaxWaitTime int = 1000
	// 30分钟
	TcpPoolLifeTime int64 = 1800
)

tcp请求信息

View Source
const (
	StatusZero int = iota
	StatusOne
	StatusTwo
)

status

View Source
const (
	MsgTypeNone uint32 = iota
	MsgTypeRequest
	MsgTypeResponse
	MsgTypeNotice
	MsgTypePush
)

msg type

View Source
const (
	HandleKeySession string = "Session"
	HandleKeyMid     string = "Mid"
	MemberNode       string = "MemberNode"
	ServerNode       string = "ServerNode"
	MchIDKey         string = "MchID"
	SessionIDKey     string = "SessionID"
	MessageDeal      string = "MessageDeal"
)

handle key

View Source
const (
	MinUint64     uint64 = 0
	MaxUint64     uint64 = ^uint64(0)
	MemberSidSize uint64 = 10000
	MaxSessionNum uint64 = 1000000
)

一些数值

Variables

This section is empty.

Functions

func GenAddr

func GenAddr(host, port string) string

组装地址

func GetPsutil

func GetPsutil() *deal.Psutil

获取服务配置信息

func InStringArr

func InStringArr(s string, arr []string) bool

判断对象是否在字符串数组中

func MsgMarsh

func MsgMarsh(deal uint32, input interface{}) ([]byte, error)

加密协议

func MsgUnMarsh

func MsgUnMarsh(deal uint32, msg []byte, output interface{}) error

解密协议

func PacketMarsh

func PacketMarsh(p *Packet) ([]byte, error)

包转码

func PrintMsg

func PrintMsg(msg *deal.Msg, data ...interface{})

func SetConfig

func SetConfig(file string)

加载配置文件

func VersionCompare

func VersionCompare(v1, v2 string) bool

version compare

Types

type Addr

type Addr struct {
	Ip   string
	Port string
}

func ParseAddr

func ParseAddr(s string) (*Addr, error)

解析地址

type Base

type Base struct {
	// 版本号
	Version string
	// Msg协议
	TcpDeal uint32
}

type Cache

type Cache struct {
	sync.RWMutex
	Values map[string]interface{}
}

全局数据缓存

func GetCache

func GetCache() *Cache

func NewCache

func NewCache() *Cache

func (*Cache) Del

func (c *Cache) Del(k string)

删除缓存

func (*Cache) Get

func (c *Cache) Get(k string) interface{}

获取缓存

func (*Cache) GetBool

func (c *Cache) GetBool(k string) bool

获取bool

func (*Cache) GetFloat

func (c *Cache) GetFloat(k string) float64

获取int

func (*Cache) GetInt

func (c *Cache) GetInt(k string) int

获取int

func (*Cache) GetInt32

func (c *Cache) GetInt32(k string) int32

获取int32

func (*Cache) GetInt64

func (c *Cache) GetInt64(k string) int64

获取int64

func (*Cache) GetString

func (c *Cache) GetString(k string) string

获取string

func (*Cache) GetUInt

func (c *Cache) GetUInt(k string) uint

获取int

func (*Cache) GetUInt32

func (c *Cache) GetUInt32(k string) uint32

获取int32

func (*Cache) GetUInt64

func (c *Cache) GetUInt64(k string) uint64

获取uint64

func (*Cache) Set

func (c *Cache) Set(k string, v interface{})

设置缓存

type Config

type Config struct {
	Base Base

	Server Server

	Master Master

	Member Member
}

func GetConfig

func GetConfig() *Config

获取配置

type Master

type Master struct {
	TcpAddr  string
	HttpAddr string
}

type Member

type Member struct {
	// tcp对外地址
	TcpAddr string
	// tcp对内地址
	InnerAddr string
	// 主节点地址
	MasterAddr string
}

type Packet

type Packet struct {
	// 数据源长度
	Length uint16
	// 源数据
	Data []byte
}

tcp数据包结构

func PacketUnMarsh

func PacketUnMarsh(bys []byte) (int, []*Packet)

包解析 返回占用字节数、包、错误

type Server

type Server struct {
	// 服务器地址
	TcpAddr string

	// 通信的网关地址
	MasterAddr string
}

Jump to

Keyboard shortcuts

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