util

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidPortRange     = errors.New("invalid port range")
	ErrInvalidAddressFormat = errors.New("invalid address format")
)
View Source
var (
	ErrMaxPacket  = errors.New("packet over size")
	ErrMinPacket  = errors.New("packet short size")
	ErrShortMsgID = errors.New("short msgid")
)

Functions

func BytesMD5

func BytesMD5(data []byte) string

字节计算MD5

func CompressBytes

func CompressBytes(data []byte) ([]byte, error)

压缩字节

func DecompressBytes

func DecompressBytes(data []byte) ([]byte, error)

解压字节

func DetectPort

func DetectPort(addr string, fn func(a *Address, port int) (interface{}, error)) (interface{}, error)

在给定的端口范围内找到一个能用的端口 addr格式参考ParseAddress函数

func FileExists

func FileExists(name string) bool

检查文件是否存在

func FileSize

func FileSize(name string) int64

获取文件大小

func GetLocalIP

func GetLocalIP() string

获取本地IP地址,有多重IP时,默认取第一个

func GetPrivateIPv4

func GetPrivateIPv4() ([]*net.IPAddr, error)

获得本机的IPV4的地址

func GetPublicIPv6

func GetPublicIPv6() ([]*net.IPAddr, error)

获得本机的IPV6地址

func GetRemoteAddrss

func GetRemoteAddrss(ses cellnet.Session) (string, bool)

获取session远程的地址

func IsEOFOrNetReadError

func IsEOFOrNetReadError(err error) bool

判断网络错误

func JoinAddress

func JoinAddress(host string, port int) string

将host和端口合并为(host:port)格式的地址

func ReadFileLines

func ReadFileLines(filename string, callback func(line string) bool) error

读取文本文件的所有行

func ReadKVFile

func ReadKVFile(filename string, callback func(k, v string) bool) (ret error)

读取=分割的配置文件

func RecvLTVPacket

func RecvLTVPacket(reader io.Reader, maxPacketSize int) (msg interface{}, err error)

接收Length-Type-Value格式的封包流程

func SendLTVPacket

func SendLTVPacket(writer io.Writer, ctx cellnet.ContextSet, data interface{}) error

发送Length-Type-Value格式的封包流程

func SpliteAddress

func SpliteAddress(addr string) (host string, port int, err error)

将普通地址格式(host:port)拆分

func StackToString

func StackToString(count int) string

给定打印层数,一般3~5覆盖你的逻辑及封装代码范围

func StringHash

func StringHash(s string) (hash uint16)

字符串转为16位整形哈希

func StringMD5

func StringMD5(str string) string

字符串计算MD5

func WriteFull

func WriteFull(writer io.Writer, buf []byte) error

完整发送所有封包

Types

type Address

type Address struct {
	Scheme  string
	Host    string
	MinPort int
	MaxPort int
	Path    string
}

支持地址范围的格式

func ParseAddress

func ParseAddress(addr string) (addrObj *Address, err error)

cellnet专有的地址格式 scheme://host:minPort~maxPort/path 提供地址范围扩展

func (*Address) HostPortString

func (self *Address) HostPortString(port int) string

返回(host:port)格式地址

func (*Address) String

func (self *Address) String(port int) string

返回scheme://host:port/path 格式地址

type KVPair

type KVPair struct {
	Key   string
	Value string
}

func ReadKVFileValues

func ReadKVFileValues(filename string) (ret []KVPair, err error)

将=分割的文件按值读回

type Queue

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

func NewQueue

func NewQueue(size int) *Queue

func (*Queue) Clear

func (self *Queue) Clear()

func (*Queue) Count

func (self *Queue) Count() int

func (*Queue) Dequeue

func (self *Queue) Dequeue() (ret interface{})

func (*Queue) Enqueue

func (self *Queue) Enqueue(data interface{})

func (*Queue) Peek

func (self *Queue) Peek() interface{}

type RemoteAddr

type RemoteAddr interface {
	RemoteAddr() net.Addr
}

修复ws没有实现所有net.conn方法,导致无法获取客服端地址问题.

Jump to

Keyboard shortcuts

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