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.
func IsServerClose ¶
IsServerClose returns true if the error is caused by server 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.
type ClientOption ¶
type ClientOption func(*clientOptions)
ClientOption is a functional option 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.
func WithResponseHeader ¶
func WithResponseHeader(header http.Header) ServerOption
WithResponseHeader sets the response header for the WebSocket upgrade response.
func WithUpgrader ¶
func WithUpgrader(upgrader *websocket.Upgrader) ServerOption
WithUpgrader sets the WebSocket upgrader for the server.