astiws

package module
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2024 License: MIT Imports: 9 Imported by: 3 modules, 4 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

// TODO

Documentation

Index

Constants

View Source
const (
	EventNameDisconnect = "astiws.disconnect"
)

Constants

Variables

This section is empty.

Functions

This section is empty.

Types

type BodyMessage

type BodyMessage struct {
	EventName string      `json:"event_name"`
	Payload   interface{} `json:"payload"`
}

BodyMessage represents the body of a message

type BodyMessageRead

type BodyMessageRead struct {
	BodyMessage
	Payload json.RawMessage `json:"payload"`
}

BodyMessageRead represents the body of a message for read purposes Indeed when reading the body, we need the payload to be a json.RawMessage

type Client

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

Client represents a websocket client

func NewClient

NewClient creates a new client

func NewClientWithContext added in v1.0.1

func NewClientWithContext(ctx context.Context, cfg ClientConfiguration, l astikit.StdLogger) (c *Client)

NewClientWithContext creates a new client with a context

func (*Client) AddListener

func (c *Client) AddListener(eventName string, f ListenerFunc)

AddListener adds a listener

func (*Client) Close

func (c *Client) Close() error

Close closes the client properly

func (*Client) CloseWithCode added in v1.3.0

func (c *Client) CloseWithCode(closeCode int) (err error)

CloseWithCode closes the client with a specific code

func (*Client) Context added in v1.0.1

func (c *Client) Context() context.Context

Context return the client's context

func (*Client) DelListener

func (c *Client) DelListener(eventName string)

DelListener deletes a listener

func (*Client) Dial

func (c *Client) Dial(addr string) error

Dial dials an addr

func (*Client) DialAndRead added in v1.1.0

func (c *Client) DialAndRead(w *astikit.Worker, o DialAndReadOptions)

DialAndReadOptions dials and read with options It's the responsibility of the caller to close the Client

func (*Client) DialWithHeaders

func (c *Client) DialWithHeaders(addr string, h http.Header) (err error)

DialWithHeader dials an addr with specific headers

func (*Client) ExtendConnection added in v1.0.1

func (c *Client) ExtendConnection() error

ExtendConnection extends the connection

func (*Client) Read

func (c *Client) Read() error

Read reads from the client

func (*Client) SetListener

func (c *Client) SetListener(eventName string, f ListenerFunc)

SetListener sets a listener

func (*Client) SetMessageHandler added in v1.0.1

func (c *Client) SetMessageHandler(h MessageHandler)

SetMessageHandler sets the message handler

func (*Client) WithContext added in v1.0.1

func (c *Client) WithContext(ctx context.Context) *Client

WithContext updates the client's context

func (*Client) Write

func (c *Client) Write(eventName string, payload interface{}) error

Write writes a message to the client

func (*Client) WriteJSON added in v1.0.1

func (c *Client) WriteJSON(m interface{}) (err error)

WriteJSON writes a JSON message to the client

func (*Client) WriteText added in v1.0.1

func (c *Client) WriteText(m []byte) (err error)

WriteText writes a text message to the client

type ClientAdapter

type ClientAdapter func(c *Client) error

type ClientConfiguration

type ClientConfiguration struct {
	MaxMessageSize int `toml:"max_message_size"`
	// Timeout after which connections are closed. If Timeout <= 0, default timeout is used.
	Timeout time.Duration `toml:"timeout"`
}

ClientConfiguration represents a client configuration

type DialAndReadOptions added in v1.1.0

type DialAndReadOptions struct {
	Addr        string
	Header      http.Header
	OnDial      func() error
	OnReadError func(err error)
}

DialAndReadOptions represents dial and read options

type ListenerFunc

type ListenerFunc func(c *Client, eventName string, payload json.RawMessage) error

ListenerFunc represents a listener callback

type MessageHandler added in v1.0.1

type MessageHandler func(m []byte) error

MessageHandler represents a message handler

type OnServeError added in v1.7.0

type OnServeError func(*Client, error)

type Server added in v1.7.0

type Server struct {
	Upgrader websocket.Upgrader
	// contains filtered or unexported fields
}

func NewServer added in v1.7.0

func NewServer(o ServerOptions) *Server

func (*Server) Clients added in v1.7.0

func (s *Server) Clients() []*Client

func (*Server) Close added in v1.7.0

func (s *Server) Close() error

func (*Server) ServeHTTP added in v1.7.0

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ServerOptions added in v1.7.0

type ServerOptions struct {
	CheckOrigin    func(r *http.Request) bool
	ClientAdapter  ClientAdapter
	Logger         astikit.StdLogger
	MaxMessageSize int
	OnServeError   OnServeError
	Timeout        time.Duration
}

Jump to

Keyboard shortcuts

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