websocket

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2021 License: MIT Imports: 17 Imported by: 1

Documentation

Index

Constants

View Source
const (
	WebsocketFlagClosed = iota
	WebsocketFlagIdle

	WebsocketFlagMax
)
View Source
const (
	FlagRunning = iota
	FlagClosed

	FlagFrozen
	FlagActive

	FlagMax
)

Variables

View Source
var (
	ErrClosed    = errors.New("conn closed")
	ErrListAdd   = errors.New("unable add to list")
	ErrBadInput  = errors.New("bad input")
	ErrEmptyData = errors.New("empty data")
)

Functions

func CoroutineGo

func CoroutineGo(fn func())

func GenUUID

func GenUUID() (string, error)

func InitCoroutinePool

func InitCoroutinePool(p *ants.Pool)

func IsDialTimeout

func IsDialTimeout(err error) bool

Types

type Client

type Client struct {
	sync.RWMutex

	sync.Pool
	// contains filtered or unexported fields
}

func NewClient

func NewClient() *Client

func (*Client) Close

func (this *Client) Close()

func (*Client) Dial

func (this *Client) Dial(urlStr string, args ...interface{}) (*Conn, error)

func (*Client) GetConnByID

func (this *Client) GetConnByID(id string) *Conn

func (*Client) Len

func (this *Client) Len() int

func (*Client) Lists

func (this *Client) Lists() []string

func (*Client) SetNetDial added in v0.0.5

func (this *Client) SetNetDial(fn func(network, addr string) (net.Conn, error))

func (*Client) SetTLSConfig

func (this *Client) SetTLSConfig(config *tls.Config)

type ClientDialer added in v0.0.4

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

func NewClientDialer added in v0.0.4

func NewClientDialer(client *Client, url string) *ClientDialer

func (*ClientDialer) Dial added in v0.0.4

func (this *ClientDialer) Dial(network, addr string) (net.Conn, error)

func (*ClientDialer) SetHandler added in v0.0.4

func (this *ClientDialer) SetHandler(fn func(net.Conn, string, string) (net.Conn, error))

func (*ClientDialer) SetTimeout added in v0.0.4

func (this *ClientDialer) SetTimeout(d time.Duration)

type Conn

type Conn struct {
	*websocket.Conn

	*Values

	sync.Mutex
	// contains filtered or unexported fields
}

func (*Conn) AddCloseHandler

func (this *Conn) AddCloseHandler(args ...interface{})

func (*Conn) AddPongHandler

func (this *Conn) AddPongHandler(args ...interface{})

func (*Conn) Close

func (this *Conn) Close() error

func (*Conn) HandleConn

func (this *Conn) HandleConn(fn func(*Conn, string))

func (*Conn) ID

func (this *Conn) ID() string

func (*Conn) Read

func (this *Conn) Read(data []byte) (int, error)

func (*Conn) SetDeadline added in v0.0.4

func (this *Conn) SetDeadline(t time.Time) error

func (*Conn) SetIsolatorTime

func (this *Conn) SetIsolatorTime(timeout time.Duration)

func (*Conn) StartIdlaCheck

func (this *Conn) StartIdlaCheck(timeout time.Duration, fns ...func(uint64, uint64))

func (*Conn) UnSetIsolatorTime

func (this *Conn) UnSetIsolatorTime()

func (*Conn) Write

func (this *Conn) Write(data []byte) (int, error)

func (*Conn) WriteJSON

func (this *Conn) WriteJSON(v interface{}) (int, error)

func (*Conn) WriteMessage

func (this *Conn) WriteMessage(messageType int, data []byte) error

func (*Conn) WriteString

func (this *Conn) WriteString(msg string) error

type JsonEncoder

type JsonEncoder struct {
	sync.Mutex

	*bytes.Buffer
	*json.Encoder
}

func NewJsonEncoder

func NewJsonEncoder() *JsonEncoder

func (*JsonEncoder) Bytes

func (this *JsonEncoder) Bytes() []byte

func (*JsonEncoder) Encode

func (this *JsonEncoder) Encode(v interface{}) error

func (*JsonEncoder) String

func (this *JsonEncoder) String() string

type Server

type Server struct {
	sync.Mutex

	sync.Pool // for websocket.Upgrader::WriteBufferPool
	// contains filtered or unexported fields
}

func NewServer

func NewServer(fn func(*Conn, string)) *Server

func (*Server) AddAuthHandler

func (this *Server) AddAuthHandler(fn func(*Values, interface{}) bool)

func (*Server) AddConnectedHandler

func (this *Server) AddConnectedHandler(fn func(*Conn) bool)

func (*Server) AddRawConnectionHandler

func (this *Server) AddRawConnectionHandler(fn func(*Conn))

func (*Server) BroadCastData

func (this *Server) BroadCastData(data []byte) error

func (*Server) BroadCastJSON

func (this *Server) BroadCastJSON(v interface{}) error

func (*Server) BroadCastString

func (this *Server) BroadCastString(msg string) error

func (*Server) Close

func (this *Server) Close()

func (*Server) GetConnByID

func (this *Server) GetConnByID(id string) *Conn

func (*Server) Lists

func (this *Server) Lists() []string

func (*Server) Upgrade

func (this *Server) Upgrade(w http.ResponseWriter, r *http.Request, args ...interface{})

func (*Server) UpgradeWithValues added in v0.0.5

func (this *Server) UpgradeWithValues(w http.ResponseWriter, r *http.Request, v *Values, args ...interface{})

type Values

type Values struct {
	sync.Map
}

func (*Values) KVClear

func (this *Values) KVClear()

func (*Values) KVGet

func (this *Values) KVGet(key string) interface{}

func (*Values) KVGetBoolean

func (this *Values) KVGetBoolean(key string, def ...bool) bool

func (*Values) KVGetByte

func (this *Values) KVGetByte(key string, def ...byte) byte

func (*Values) KVGetInt

func (this *Values) KVGetInt(key string, def ...int) int

func (*Values) KVGetInt64

func (this *Values) KVGetInt64(key string, def ...int64) int64

func (*Values) KVGetString

func (this *Values) KVGetString(key string, def ...string) string

func (*Values) KVSet

func (this *Values) KVSet(key string, value interface{})

func (*Values) KVUnSet

func (this *Values) KVUnSet(key string)

func (*Values) String added in v0.0.5

func (this *Values) String() string

Jump to

Keyboard shortcuts

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