Documentation
¶
Index ¶
- Constants
- Variables
- func ReleaseFrame(fr *Frame)
- func UpgradeAsClient(c net.Conn, url string, r *fasthttp.Request) error
- type Client
- func ClientWithHeaders(c net.Conn, url string, req *fasthttp.Request) (*Client, error)
- func Dial(url string) (*Client, error)
- func DialTLS(url string, cnf *tls.Config) (*Client, error)
- func DialWithHeaders(url string, req *fasthttp.Request) (*Client, error)
- func MakeClient(c net.Conn, url string) (*Client, error)
- type CloseHandler
- type Code
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) ID() uint64
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) Ping(data []byte)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) SetUserValue(key string, value interface{})
- func (c *Conn) UserValue(key string) interface{}
- func (c *Conn) Write(data []byte) (int, error)
- func (c *Conn) WriteFrame(fr *Frame)
- type Error
- type ErrorHandler
- type Frame
- func (fr *Frame) Code() Code
- func (fr *Frame) CopyTo(fr2 *Frame)
- func (fr *Frame) HasRSV1() bool
- func (fr *Frame) HasRSV2() bool
- func (fr *Frame) HasRSV3() bool
- func (fr *Frame) IsClose() bool
- func (fr *Frame) IsContinuation() bool
- func (fr *Frame) IsControl() bool
- func (fr *Frame) IsFin() bool
- func (fr *Frame) IsMasked() bool
- func (fr *Frame) IsPing() bool
- func (fr *Frame) IsPong() bool
- func (fr *Frame) Len() (length uint64)
- func (fr *Frame) Mask()
- func (fr *Frame) MaskKey() []byte
- func (fr *Frame) Payload() []byte
- func (fr *Frame) PayloadLen() int
- func (fr *Frame) PayloadSize() uint64
- func (fr *Frame) ReadFrom(rd io.Reader) (int64, error)
- func (fr *Frame) Reset()
- func (fr *Frame) SetBinary()
- func (fr *Frame) SetClose()
- func (fr *Frame) SetCode(code Code)
- func (fr *Frame) SetContinuation()
- func (fr *Frame) SetFin()
- func (fr *Frame) SetMask(b []byte)
- func (fr *Frame) SetPayload(b []byte)
- func (fr *Frame) SetPayloadSize(size uint64)
- func (fr *Frame) SetPing()
- func (fr *Frame) SetPong()
- func (fr *Frame) SetRSV1()
- func (fr *Frame) SetRSV2()
- func (fr *Frame) SetRSV3()
- func (fr *Frame) SetStatus(status StatusCode)
- func (fr *Frame) SetText()
- func (fr *Frame) Status() (status StatusCode)
- func (fr *Frame) String() string
- func (fr *Frame) Unmask()
- func (fr *Frame) UnsetMask()
- func (fr *Frame) Write(b []byte) (int, error)
- func (fr *Frame) WriteTo(wr io.Writer) (n int64, err error)
- type FrameHandler
- type MessageHandler
- type OpenHandler
- type PingHandler
- type PongHandler
- type RequestHandler
- type Server
- func (s *Server) HandleClose(closeHandler CloseHandler)
- func (s *Server) HandleData(msgHandler MessageHandler)
- func (s *Server) HandleError(errHandler ErrorHandler)
- func (s *Server) HandleFrame(frameHandler FrameHandler)
- func (s *Server) HandleOpen(openHandler OpenHandler)
- func (s *Server) HandlePing(pingHandler PingHandler)
- func (s *Server) HandlePong(pongHandler PongHandler)
- func (s *Server) Upgrade(ctx *fasthttp.RequestCtx)
- type StatusCode
- type UpgradeHandler
Constants ¶
const ( // StatusNone is used to let the peer know nothing happened. StatusNone StatusCode = 1000 // StatusGoAway peer's error. StatusGoAway = 1001 // StatusProtocolError problem with the peer's way to communicate. StatusProtocolError = 1002 // StatusNotAcceptable when a request is not acceptable StatusNotAcceptable = 1003 // StatusReserved when a reserved field have been used StatusReserved = 1004 // StatusNotConsistent IDK StatusNotConsistent = 1007 // StatusViolation a violation of the protocol happened StatusViolation = 1008 // StatusTooBig payload bigger than expected StatusTooBig = 1009 // StatuseExtensionsNeeded IDK StatuseExtensionsNeeded = 1010 // StatusUnexpected IDK StatusUnexpected = 1011 )
const DefaultPayloadSize = 1 << 20
DefaultPayloadSize defines the default payload size (when none was defined).
Variables ¶
var ( // EOF represents an io.EOF error. EOF = io.EOF )
var ( // ErrCannotUpgrade shows up when an error occurred when upgrading a connection. ErrCannotUpgrade = errors.New("cannot upgrade connection") )
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client ...
func ClientWithHeaders ¶
ClientWithHeaders returns a Conn using existing connection and sending personalized headers.
func Dial ¶
Dial establishes a websocket connection as client.
url parameter must follow WebSocket URL format i.e. ws://host:port/path
func DialTLS ¶
DialTLS establishes a websocket connection as client with the parsed tls.Config. The config will be used if the URL is wss:// like.
func DialWithHeaders ¶
DialWithHeaders establishes a websocket connection as client sending a personalized request.
func MakeClient ¶
MakeClient returns Conn using existing connection.
url must be complete URL format i.e. http://localhost:8080/ws
type CloseHandler ¶
type Code ¶
type Code uint8
Code to send.
const ( // CodeContinuation defines the continuation code CodeContinuation Code = 0x0 // CodeText defines the text code CodeText Code = 0x1 // CodeBinary defines the binary code CodeBinary Code = 0x2 // CodeClose defines the close code CodeClose Code = 0x8 // CodePing defines the ping code CodePing Code = 0x9 // CodePong defines the pong code CodePong Code = 0xA )
type Conn ¶ added in v0.0.3
type Conn struct {
// ReadTimeout ...
ReadTimeout time.Duration
// WriteTimeout ...
WriteTimeout time.Duration
// MaxPayloadSize prevents huge memory allocation.
//
// By default MaxPayloadSize is DefaultPayloadSize.
MaxPayloadSize uint64
// contains filtered or unexported fields
}
Conn represents a WebSocket connection on the server side.
This handler is compatible with io.Writer.
func (*Conn) RemoteAddr ¶ added in v0.0.3
RemoteAddr returns peer remote address.
func (*Conn) SetUserValue ¶ added in v0.0.3
SetUserValue assigns a key to the given value
func (*Conn) WriteFrame ¶ added in v0.0.3
type Error ¶
type Error struct {
Status StatusCode
Reason string
}
type ErrorHandler ¶
type Frame ¶
type Frame struct {
// contains filtered or unexported fields
}
Frame is the unit used to transfer message between endpoints using the websocket protocol.
func (*Frame) IsContinuation ¶
IsContinuation returns true if the Frame code is Continuation
func (*Frame) IsControl ¶
IsControl returns whether the Frame is a control frame or not. That means if it's a Close, Ping or Pong frame.
func (*Frame) Len ¶
Len returns the length of the payload based on the header bits.
If you want to know the actual payload length use #PayloadLen
func (*Frame) PayloadLen ¶
PayloadLen returns the actual payload length
func (*Frame) PayloadSize ¶
PayloadSize returns the max payload size
func (*Frame) SetContinuation ¶
func (fr *Frame) SetContinuation()
SetContinuation sets CodeContinuation in Code field.
func (*Frame) SetPayload ¶
SetPayload sets the parsed bytes as frame's payload
func (*Frame) SetPayloadSize ¶
SetPayloadSize sets max payload size
func (*Frame) SetStatus ¶
func (fr *Frame) SetStatus(status StatusCode)
SetStatus sets status code.
Status code is usually used in Close request.
func (*Frame) Unmask ¶
func (fr *Frame) Unmask()
Unmask performs the unmasking of the current payload
type FrameHandler ¶
type MessageHandler ¶
type PingHandler ¶
type PongHandler ¶
type RequestHandler ¶
type RequestHandler func(conn *Conn)
RequestHandler is the websocket connection handler.
type Server ¶
type Server struct {
// UpgradeHandler allows user to handle RequestCtx when upgrading.
//
// If UpgradeHandler returns false the connection won't be upgraded and
// the parsed ctx will be used as a response.
UpgradeHandler UpgradeHandler
// Protocols are the supported protocols.
Protocols []string
// Origin is used to limit the clients coming from the defined origin
Origin string
// contains filtered or unexported fields
}
Server represents the WebSocket server.
Server is going to be in charge of upgrading the connection, is not a server per-se.
func (*Server) HandleClose ¶
func (s *Server) HandleClose(closeHandler CloseHandler)
func (*Server) HandleData ¶
func (s *Server) HandleData(msgHandler MessageHandler)
HandleData sets the MessageHandler.
func (*Server) HandleError ¶
func (s *Server) HandleError(errHandler ErrorHandler)
func (*Server) HandleFrame ¶
func (s *Server) HandleFrame(frameHandler FrameHandler)
func (*Server) HandleOpen ¶
func (s *Server) HandleOpen(openHandler OpenHandler)
func (*Server) HandlePing ¶
func (s *Server) HandlePing(pingHandler PingHandler)
func (*Server) HandlePong ¶
func (s *Server) HandlePong(pongHandler PongHandler)
func (*Server) Upgrade ¶
func (s *Server) Upgrade(ctx *fasthttp.RequestCtx)
type StatusCode ¶
type StatusCode uint16
StatusCode is sent when closing a connection.
The following constants have been defined by the RFC.
func (StatusCode) String ¶
func (status StatusCode) String() string
type UpgradeHandler ¶
type UpgradeHandler func(*fasthttp.RequestCtx) bool
UpgradeHandler is the upgrading handler.