ws

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewWrapConnection

func NewWrapConnection(netConn net.Conn) *connection

Types

type Conn

type Conn interface {
	ID() string
	Push(msg []byte) error
	IP() string
	Property() *Property
}

Conn websocket connection

type Context

type Context struct {
	context.Context
	// contains filtered or unexported fields
}

func NewContext

func NewContext(conn Conn, body []byte) *Context

func (*Context) Body

func (ctx *Context) Body() []byte

func (*Context) Conn

func (ctx *Context) Conn() Conn

func (*Context) Output

func (ctx *Context) Output(msg []byte)

type Property

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

func (*Property) Get

func (p *Property) Get(key string) any

func (*Property) GetString

func (p *Property) GetString(key string) string

func (*Property) Set

func (p *Property) Set(key string, value any)

type Server

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

Server provide the websocket server.

func NewServer

func NewServer(bind string) *Server

func (*Server) OnConnect

func (server *Server) OnConnect(handler func(conn Conn)) *Server

OnConnect is set callback when the connection is established

func (*Server) OnDisconnect

func (server *Server) OnDisconnect(handler func(conn Conn)) *Server

OnDisconnect is set callback when the client disconnects from the server

func (*Server) OnMessage

func (server *Server) OnMessage(handler func(ctx *Context)) *Server

OnMessage is set callback when a message is received.

func (*Server) Serve

func (server *Server) Serve(stop <-chan struct{})

Serve start websocket server

func (*Server) Shutdown

func (server *Server) Shutdown()

Shutdown stop websocket server.

func (*Server) WithWorker

func (server *Server) WithWorker(worker int) *Server

WithWorker sets the concurrent worker threads.

Jump to

Keyboard shortcuts

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