Documentation
¶
Overview ¶
Package ws provides a websocket server implementation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsClientClose ¶
IsClientClose returns true if the error is caused by client close.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a wrapper of gorilla/websocket.
func NewClient ¶
func NewClient(url string, opts ...ClientOption) (*Client, error)
NewClient creates a new client.
func (*Client) Close ¶
Close closes the connection. Note: if set pingDialInterval, the Close method must be called, otherwise it will cause the goroutine to leak
func (*Client) TryReconnect ¶ added in v1.10.2
TryReconnect tries to reconnect the websocket server.
type ClientOption ¶
type ClientOption func(*clientOptions)
ClientOption is a functional option for the client.
func WithClientLogger ¶ added in v1.10.2
func WithClientLogger(l *zap.Logger) ClientOption
WithClientLogger sets the logger for the client.
func WithDialer ¶
func WithDialer(dialer *websocket.Dialer) ClientOption
WithDialer sets the dialer for the client.
func WithPing ¶
func WithPing(interval time.Duration) ClientOption
WithPing sets the interval for sending ping message to the server.
func WithRequestHeader ¶
func WithRequestHeader(header http.Header) ClientOption
WithRequestHeader sets the request header for the client.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a WebSocket server.
func NewServer ¶
func NewServer(w http.ResponseWriter, r *http.Request, loopFn LoopFn, opts ...ServerOption) *Server
NewServer creates a new WebSocket server.
type ServerOption ¶
type ServerOption func(*serverOptions)
ServerOption is a functional option for the Server.
func WithMaxMessageWaitPeriod ¶
func WithMaxMessageWaitPeriod(period time.Duration) ServerOption
WithMaxMessageWaitPeriod sets the maximum waiting period for a message before closing the connection. Deprecated: use WithNoClientPingTimeout instead.
func WithNoClientPingTimeout ¶ added in v1.10.2
func WithNoClientPingTimeout(timeout time.Duration) ServerOption
WithNoClientPingTimeout sets the timeout for the client to send a ping message, if timeout, the connection will be closed.
func WithResponseHeader ¶
func WithResponseHeader(header http.Header) ServerOption
WithResponseHeader sets the response header for the WebSocket upgrade response.
func WithServerLogger ¶ added in v1.10.2
func WithServerLogger(l *zap.Logger) ServerOption
WithServerLogger sets the logger for the server.
func WithUpgrader ¶
func WithUpgrader(upgrader *websocket.Upgrader) ServerOption
WithUpgrader sets the WebSocket upgrader for the server.