util

package
v3.6.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2018 License: LGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConnClosing   = errors.New("use of closed network connection")
	ErrWriteBlocking = errors.New("write packet was blocking")
	ErrReadBlocking  = errors.New("read packet was blocking")
)

Error type

Functions

func AppendToFile

func AppendToFile(fileName string, content string) error

AppendToFile 文件名字(带全路径) content: 写入的内容

func ExternalIP

func ExternalIP() (net.IP, error)

ExternalIP 获取本机ip

func Format

func Format(source map[string]gjson.Result) map[string]interface{}

Format 格式化处理监控数据

func GetHostID

func GetHostID(nodeIDFile string) (string, error)

GetHostID 获取机器ID

func Source

func Source(l *logrus.Entry) *logrus.Entry

Types

type Buffer

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

func NewBuffer

func NewBuffer(source []byte) *Buffer

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

func (*Buffer) Cap

func (b *Buffer) Cap() int

func (*Buffer) Grow

func (b *Buffer) Grow(n int)

func (*Buffer) Len

func (b *Buffer) Len() int

func (*Buffer) Next

func (b *Buffer) Next(n int) []byte

func (*Buffer) Read

func (b *Buffer) Read(p []byte) (n int, err error)

func (*Buffer) ReadByte

func (b *Buffer) ReadByte() (c byte, err error)

func (*Buffer) ReadBytes

func (b *Buffer) ReadBytes(delim byte) (line []byte, err error)

func (*Buffer) ReadFrom

func (b *Buffer) ReadFrom(r io.Reader) (n int64, err error)

func (*Buffer) ReadRune

func (b *Buffer) ReadRune() (r rune, size int, err error)

func (*Buffer) ReadString

func (b *Buffer) ReadString(delim byte) (line string, err error)

func (*Buffer) Reset

func (b *Buffer) Reset()

func (*Buffer) String

func (b *Buffer) String() string

func (*Buffer) Truncate

func (b *Buffer) Truncate(n int)

func (*Buffer) UnreadByte

func (b *Buffer) UnreadByte() error

func (*Buffer) UnreadRune

func (b *Buffer) UnreadRune() error

func (*Buffer) Write

func (b *Buffer) Write(p []byte) (n int, err error)

func (*Buffer) WriteByte

func (b *Buffer) WriteByte(c byte) error

func (*Buffer) WriteRune

func (b *Buffer) WriteRune(r rune) (n int, err error)

func (*Buffer) WriteString

func (b *Buffer) WriteString(s string) (n int, err error)

func (*Buffer) WriteTo

func (b *Buffer) WriteTo(w io.Writer) (n int64, err error)

type Config

type Config struct {
	PacketSendChanLimit    uint32 // the limit of packet send channel
	PacketReceiveChanLimit uint32 // the limit of packet receive channel
}

type Conn

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

Conn exposes a set of callbacks for the various events that occur on a connection

func (*Conn) AsyncWritePacket

func (c *Conn) AsyncWritePacket(p Packet, timeout time.Duration) (err error)

AsyncWritePacket async writes a packet, this method will never block

func (*Conn) Close

func (c *Conn) Close()

Close closes the connection

func (*Conn) Do

func (c *Conn) Do()

Do it

func (*Conn) GetExtraData

func (c *Conn) GetExtraData() interface{}

GetExtraData gets the extra data from the Conn

func (*Conn) GetRawConn

func (c *Conn) GetRawConn() *net.TCPConn

GetRawConn returns the raw net.TCPConn from the Conn

func (*Conn) IsClosed

func (c *Conn) IsClosed() bool

IsClosed indicates whether or not the connection is closed

func (*Conn) PutExtraData

func (c *Conn) PutExtraData(data interface{})

PutExtraData puts the extra data with the Conn

type ConnCallback

type ConnCallback interface {
	// OnConnect is called when the connection was accepted,
	// If the return value of false is closed
	OnConnect(*Conn) bool

	// OnMessage is called when the connection receives a packet,
	// If the return value of false is closed
	OnMessage(Packet) bool

	// OnClose is called when the connection closed
	OnClose(*Conn)
}

ConnCallback is an interface of methods that are used as callbacks on a connection

type MessagePacket

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

func (*MessagePacket) IsNull

func (m *MessagePacket) IsNull() bool

func (*MessagePacket) IsPing

func (m *MessagePacket) IsPing() bool

func (*MessagePacket) Serialize

func (m *MessagePacket) Serialize() []byte

type MessageProtocol

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

func (*MessageProtocol) Decode

func (m *MessageProtocol) Decode() (string, error)

Decode 解码数据流

func (*MessageProtocol) ReadPacket

func (m *MessageProtocol) ReadPacket() (Packet, error)

ReadPacket 获取消息流

func (*MessageProtocol) SetConn

func (m *MessageProtocol) SetConn(conn *net.TCPConn)

type Packet

type Packet interface {
	Serialize() []byte
	IsNull() bool
	IsPing() bool
}

type Protocol

type Protocol interface {
	SetConn(conn *net.TCPConn)
	ReadPacket() (Packet, error)
}

type Server

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

func NewServer

func NewServer(config *Config, callback ConnCallback, ctx context.Context) *Server

NewServer creates a server

func (*Server) Start

func (s *Server) Start(listener *net.TCPListener, acceptTimeout time.Duration)

Start starts service

func (*Server) Stop

func (s *Server) Stop()

Stop stops service

Jump to

Keyboard shortcuts

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