util

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

func BytesMD5

func BytesMD5(data []byte) string

func DetectPort

func DetectPort(addrStr string, fn func(addr *Addr, port int) (interface{}, error)) (interface{}, error)

func FileExists

func FileExists(name string) bool

检查文件是否存在

func FileSize

func FileSize(name string) int64

获取文件大小

func GetRemoteAddress

func GetRemoteAddress(ses void.Session) (string, bool)

获取session远程的地址

func IsEOFOrNetReadError

func IsEOFOrNetReadError(err error) bool

判断网络错误

func JoinAddress

func JoinAddress(host string, port int) string

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

func Pack

func Pack(writer io.Writer, data interface{}) error

封包(LTV, Length-Type-Value)

func ReadFileLines

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

读取文本文件的所有行

func SplitAddress

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

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

func StringHash

func StringHash(s string) (hash uint16)

func StringMD5

func StringMD5(s string) string

func Unpack

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

拆包(LTV, Length-Type-Value)

func WriteFull

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

完整发送所有封包

Types

type Addr

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

func ParseAddr

func ParseAddr(addrStr string) (addr *Addr, err error)

ParseAddr format: scheme://host:minPort~maxPort/path

func (*Addr) HostPortString

func (a *Addr) HostPortString(port int) string

HostPortString return host:port

func (*Addr) String

func (a *Addr) String(port int) string

String return scheme://host:port/path

type RemoteAddr

type RemoteAddr interface {
	RemoteAddr() net.Addr
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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