guds

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultAntsPoolSize = 1 << 18

	ExpiryDuration = 10 * time.Second

	Nonblocking = true
)

Variables

View Source
var (
	ErrTimeout = errors.New("request timeout! ")
)

Functions

func BytesToInt

func BytesToInt(b []byte) int

大端序字节转 int

func IntToBytes

func IntToBytes(n int) []byte

int 转大端序字节

func MergeBytes

func MergeBytes(b1 []byte, b2 ...[]byte) []byte

Types

type Action

type Action gnet.Action
const (
	None     Action = iota
	Close           // 连接关闭
	ShutDown        // 服务关闭
	Continue        // 消息继续
	Done            // 消息结束
)

type Callback added in v0.0.2

type Callback struct {
	Err  error
	Done bool
	Body chan interface{}
}

func (*Callback) Catch added in v0.0.2

func (c *Callback) Catch(callback func(err error)) *Callback

func (*Callback) Close added in v0.0.2

func (c *Callback) Close()

func (*Callback) Then added in v0.0.2

func (c *Callback) Then(callback func(b interface{})) *Callback

type Client added in v0.0.2

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

func DefaultClient added in v0.0.2

func DefaultClient() *Client

func NewClient added in v0.0.2

func NewClient(address string, connectTimeout time.Duration) (*Client, error)

func (*Client) Send added in v0.0.2

func (c *Client) Send(api string, context interface{}) *Callback

func (*Client) Start added in v0.0.2

func (c *Client) Start()

func (*Client) Wait added in v0.0.2

func (c *Client) Wait()

type Conn

type Conn gnet.Conn

type Data

type Data struct {
	gjson.Result
}

type Message

type Message struct {
	Api  string      `json:"api"`
	Body interface{} `json:"body,omitempty"`
	// contains filtered or unexported fields
}

func NewMessage

func NewMessage(api string, data interface{}) *Message

func (*Message) Async

func (m *Message) Async() bool

func (*Message) BodyBytes added in v0.0.5

func (m *Message) BodyBytes() []byte

func (*Message) BodyLength added in v0.0.5

func (m *Message) BodyLength() int

func (*Message) BodyStringify added in v0.0.5

func (m *Message) BodyStringify() string

func (*Message) Bytes

func (m *Message) Bytes() []byte

func (*Message) GJson

func (m *Message) GJson() gjson.Result

func (*Message) Length

func (m *Message) Length() int

func (*Message) Parse

func (m *Message) Parse(b []byte) error

func (*Message) Stringify

func (m *Message) Stringify() string

func (*Message) ToData added in v0.0.2

func (m *Message) ToData() Data

type Reply

type Reply struct {
	Async  bool
	Status Action
	Body   interface{}
}

type Router

type Router struct {
	sync.RWMutex
	Callbacks map[string]func(msg Data, c chan Reply)
}

func (*Router) Get

func (h *Router) Get(api string) func(msg Data, c chan Reply)

func (*Router) Register

func (h *Router) Register(api string, callback func(msg Data, c chan Reply))

func (*Router) Remove

func (h *Router) Remove(api string)

func (*Router) RemoveAll

func (h *Router) RemoveAll()

type Server

type Server struct {
	*gnet.EventServer
	// contains filtered or unexported fields
}

func DefaultServer added in v0.0.2

func DefaultServer() *Server

func NewServer

func NewServer(addr string, multicore bool, poolSize int, timeout time.Duration) *Server

func (*Server) OnClosed

func (u *Server) OnClosed(c gnet.Conn, err error) (action gnet.Action)

func (*Server) OnInitComplete

func (u *Server) OnInitComplete(srv gnet.Server) (action gnet.Action)

func (*Server) OnOpened

func (u *Server) OnOpened(c gnet.Conn) (out []byte, action gnet.Action)

func (*Server) React

func (u *Server) React(frame []byte, c gnet.Conn, out chan gnet.Out)

func (*Server) RecordLog

func (u *Server) RecordLog()

记录日志

func (*Server) Router

func (u *Server) Router() *Router

func (*Server) Run

func (u *Server) Run()

Jump to

Keyboard shortcuts

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