Documentation ¶
Index ¶
- Constants
- type BodyMessage
- type BodyMessageRead
- type Client
- func (c *Client) AddListener(eventName string, f ListenerFunc)
- func (c *Client) Close() error
- func (c *Client) CloseWithCode(closeCode int) (err error)
- func (c *Client) Context() context.Context
- func (c *Client) DelListener(eventName string)
- func (c *Client) Dial(addr string) error
- func (c *Client) DialAndRead(w *astikit.Worker, o DialAndReadOptions)
- func (c *Client) DialWithHeaders(addr string, h http.Header) (err error)
- func (c *Client) ExtendConnection() error
- func (c *Client) Read() error
- func (c *Client) SetListener(eventName string, f ListenerFunc)
- func (c *Client) SetMessageHandler(h MessageHandler)
- func (c *Client) WithContext(ctx context.Context) *Client
- func (c *Client) Write(eventName string, payload interface{}) error
- func (c *Client) WriteJSON(m interface{}) (err error)
- func (c *Client) WriteText(m []byte) (err error)
- type ClientAdapter
- type ClientConfiguration
- type DialAndReadOptions
- type ListenerFunc
- type MessageHandler
- type OnServeError
- type Server
- type ServerOptions
Constants ¶
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 ¶
func NewClient(c ClientConfiguration, l astikit.StdLogger) *Client
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) CloseWithCode ¶ added in v1.3.0
CloseWithCode closes the client with a specific code
func (*Client) DelListener ¶
DelListener deletes a listener
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 ¶
DialWithHeader dials an addr with specific headers
func (*Client) ExtendConnection ¶ added in v1.0.1
ExtendConnection extends the connection
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
WithContext updates the client's context
type ClientAdapter ¶
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
MessageHandler represents a message handler
type OnServeError ¶ added in v1.7.0
type Server ¶ added in v1.7.0
func NewServer ¶ added in v1.7.0
func NewServer(o ServerOptions) *Server
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 }