conn

package
v0.0.0-...-b51443a Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2022 License: BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAcount = errors.New("err account")
View Source
var ErrClosed = errors.New("conn is closed")
View Source
var ErrLogined = errors.New("account is logined")
View Source
var ErrNotLogin = errors.New("not logined")

Functions

func GenHandler

func GenHandler(h Handler) reqHandler

Types

type Connection

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

Connection wrap web socket

func New

func New(rawConn *websocket.Conn, cache *msg.Cache) *Connection

func (*Connection) IPAddr

func (c *Connection) IPAddr() string

IPAddr ip addr

func (*Connection) IsClosed

func (c *Connection) IsClosed() bool

IsClosed is closed

func (*Connection) Send

func (c *Connection) Send(raw msg.Raw)

Send send msg

type Handler

type Handler interface {
	Type() string
	Unmarshal(bs []byte) (Handler, error)
	Handle(c *Connection) error
}

type Heartbeat

type Heartbeat struct{}

func (*Heartbeat) BelongTo

func (h *Heartbeat) BelongTo(account string) bool

func (*Heartbeat) Handle

func (h *Heartbeat) Handle(c *Connection) error

func (*Heartbeat) Marshal

func (h *Heartbeat) Marshal() json.RawMessage

func (*Heartbeat) Topic

func (h *Heartbeat) Topic() string

func (*Heartbeat) Type

func (h *Heartbeat) Type() string

func (*Heartbeat) Unmarshal

func (h *Heartbeat) Unmarshal(data []byte) (Handler, error)

type LoginReq

type LoginReq struct {
	Account string `json:"account"`
}

func (*LoginReq) Handle

func (req *LoginReq) Handle(c *Connection) error

func (*LoginReq) Type

func (req *LoginReq) Type() string

func (*LoginReq) Unmarshal

func (req *LoginReq) Unmarshal(data []byte) (Handler, error)

type LogoutReq

type LogoutReq struct {
	Account string `json:"account"`
}

func (*LogoutReq) Handle

func (req *LogoutReq) Handle(c *Connection) error

func (*LogoutReq) Type

func (req *LogoutReq) Type() string

func (*LogoutReq) Unmarshal

func (req *LogoutReq) Unmarshal(data []byte) (Handler, error)

type Request

type Request struct {
	Type string          `json:"type"`
	Data json.RawMessage `json:"data"`
}

type Response

type Response struct {
	ErrMsg  string `json:"err_msg"`
	ErrCode uint64 `json:"err_code"`
}

func (*Response) BelongTo

func (res *Response) BelongTo(account string) bool

func (*Response) Marshal

func (res *Response) Marshal() json.RawMessage

func (*Response) Topic

func (res *Response) Topic() string

func (*Response) Type

func (res *Response) Type() string

type SubscribeReq

type SubscribeReq struct {
	Topics []string `json:"topics"`
}

func (*SubscribeReq) Handle

func (req *SubscribeReq) Handle(c *Connection) error

func (*SubscribeReq) Type

func (req *SubscribeReq) Type() string

func (*SubscribeReq) Unmarshal

func (req *SubscribeReq) Unmarshal(data []byte) (Handler, error)

type UnsubscribeReq

type UnsubscribeReq struct {
	Topics []string `json:"topics"`
}

func (*UnsubscribeReq) Handle

func (req *UnsubscribeReq) Handle(c *Connection) error

func (*UnsubscribeReq) Type

func (req *UnsubscribeReq) Type() string

func (*UnsubscribeReq) Unmarshal

func (req *UnsubscribeReq) Unmarshal(data []byte) (Handler, error)

Jump to

Keyboard shortcuts

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