websocket

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(w http.ResponseWriter, r *http.Request) (string, error)

func NewWebsocketServer

func NewWebsocketServer(opts ...Option) toybox.Option

func SendMessage

func SendMessage(msg InputMessage)

Types

type Client

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

type Context

type Context struct {
	Keys map[string]any
	// contains filtered or unexported fields
}

func (*Context) Get

func (c *Context) Get(key string) (value any, exists bool)

func (*Context) GetBool

func (c *Context) GetBool(key string) (b bool)

func (*Context) GetDuration

func (c *Context) GetDuration(key string) (d time.Duration)

func (*Context) GetFloat64

func (c *Context) GetFloat64(key string) (f64 float64)

func (*Context) GetInt

func (c *Context) GetInt(key string) (i int)

func (*Context) GetInt64

func (c *Context) GetInt64(key string) (i64 int64)

func (*Context) GetMessage

func (c *Context) GetMessage() InputMessage

func (*Context) GetString

func (c *Context) GetString(key string) (s string)

func (*Context) GetStringMap

func (c *Context) GetStringMap(key string) (sm map[string]any)

func (*Context) GetStringMapString

func (c *Context) GetStringMapString(key string) (sms map[string]string)

func (*Context) GetStringMapStringSlice

func (c *Context) GetStringMapStringSlice(key string) (smss map[string][]string)

func (*Context) GetStringSlice

func (c *Context) GetStringSlice(key string) (ss []string)

func (*Context) GetTime

func (c *Context) GetTime(key string) (t time.Time)

func (*Context) GetUint

func (c *Context) GetUint(key string) (ui uint)

func (*Context) GetUint64

func (c *Context) GetUint64(key string) (ui64 uint64)

func (*Context) MustGet

func (c *Context) MustGet(key string) any

func (*Context) SendMessage

func (c *Context) SendMessage(msg OutputMessage)

func (*Context) Set

func (c *Context) Set(key string, value any)

type InputMessage

type InputMessage struct {
	Id   string
	Body []byte
}

func NewMessage

func NewMessage(id string, msg []byte) InputMessage

type MessageHandleFunc

type MessageHandleFunc func(ctx *Context)

type Option

type Option func(*WebsocketServer)

func WithMessageHandler

func WithMessageHandler(handleFunc ...MessageHandleFunc) Option

func WithName

func WithName(name string) Option

type OutputMessage

type OutputMessage struct {
	Targets []string
	Body    []byte
}

func NewOutputMessage

func NewOutputMessage(body []byte, targets ...string) OutputMessage

type WebsocketServer

type WebsocketServer struct {
	ReadBufferSize    int64 `toml:"read_buffer_size"`
	WriteBufferSize   int64 `toml:"write_buffer_size"`
	MaxMsgChannelSize int64 `toml:"max_msg_channel_size"`

	WriteWait      time.Duration `toml:"write_wait"`
	PongWait       time.Duration `toml:"pong_wait"`
	PingPeriod     time.Duration `toml:"ping_period"`
	MaxMessageSize int64         `toml:"max_message_size"`
	// contains filtered or unexported fields
}

func (*WebsocketServer) IsReady

func (ws *WebsocketServer) IsReady()

func (*WebsocketServer) Name

func (ws *WebsocketServer) Name() string

func (*WebsocketServer) Ready

func (ws *WebsocketServer) Ready() bool

func (*WebsocketServer) Run

func (ws *WebsocketServer) Run(ctx context.Context) error

Jump to

Keyboard shortcuts

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