Documentation ¶
Index ¶
- Constants
- Variables
- func CheckOrigin(config *ConnConfig, req *http.Request) (err error)
- func DefaultEncodeResponse(ctx context.Context, writer *Conn, response any) error
- func DefaultErrorEncoder(ctx context.Context, err error, writer *Conn)
- func NewResponse(success bool, code int, message string, data any) error
- func Origin(config *ConnConfig, req *http.Request) (*url.URL, error)
- type Addr
- type Codec
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) Config() *ConnConfig
- func (c *Conn) IsClientConn() bool
- func (c *Conn) IsServerConn() bool
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) Read(msg []byte) (n int, err error)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) Request() *http.Request
- func (c *Conn) SetDeadline(t time.Time) error
- func (c *Conn) SetReadDeadline(t time.Time) error
- func (c *Conn) SetWriteDeadline(t time.Time) error
- func (c *Conn) Write(msg []byte) (n int, err error)
- type ConnConfig
- type DecodeRequestFunc
- type EncodeResponseFunc
- type ErrorEncoder
- type Handler
- type ProtocolError
- type Response
- type Server
- type ServerConfig
Constants ¶
View Source
const ( ContinuationFrame = 0 TextFrame = 1 BinaryFrame = 2 CloseFrame = 8 PingFrame = 9 PongFrame = 10 UnknownFrame = 255 )
View Source
const ( SupportedProtocolVersion = "13" ProtocolVersionHybi13 = 13 DefaultMaxPayloadBytes = 32 << 20 // 32MB )
Variables ¶
View Source
var ( ErrBadProtocolVersion = &ProtocolError{"bad protocol version"} ErrBadScheme = &ProtocolError{"bad scheme"} ErrBadStatus = &ProtocolError{"bad status"} ErrBadUpgrade = &ProtocolError{"missing or bad upgrade"} ErrBadWebSocketOrigin = &ProtocolError{"missing or bad WebSocket-Origin"} ErrBadWebSocketLocation = &ProtocolError{"missing or bad WebSocket-Location"} ErrBadWebSocketProtocol = &ProtocolError{"missing or bad WebSocket-Protocol"} ErrBadWebSocketVersion = &ProtocolError{"missing or bad WebSocket Version"} ErrChallengeResponse = &ProtocolError{"mismatch challenge/response"} ErrBadFrame = &ProtocolError{"bad frame2"} ErrBadFrameBoundary = &ProtocolError{"not on frame2 boundary"} ErrNotWebSocket = &ProtocolError{"not websocket protocol"} ErrBadRequestMethod = &ProtocolError{"bad method"} ErrNotSupported = &ProtocolError{"not supported"} ErrFrameTooLarge = &ProtocolError{"websocket: frame2 payload size exceeds limiter"} ErrBadMaskingKey = &ProtocolError{"bad masking key"} ErrBadPongMessage = &ProtocolError{"bad pong message"} ErrBadClosingStatus = &ProtocolError{"bad closing status"} ErrUnsupportedExtensions = &ProtocolError{"unsupported extensions"} ErrNotImplemented = &ProtocolError{"not implemented"} ErrSetDeadline = &ProtocolError{"websocket: cannot set deadline: not using a net.Conn"} )
View Source
var JSON = Codec{jsonMarshal, jsonUnmarshal}
View Source
var Message = Codec{marshal, unmarshal}
Functions ¶
func CheckOrigin ¶
func CheckOrigin(config *ConnConfig, req *http.Request) (err error)
func DefaultEncodeResponse ¶
func NewResponse ¶
NewResponse 实例化
Types ¶
type Codec ¶
type Conn ¶
func NewConn ¶
func NewConn(rwc io.ReadWriteCloser, buf *bufio.ReadWriter, req *http.Request, config *ConnConfig, handshake func(*ConnConfig, *http.Request) error) (conn *Conn, err error)
func (*Conn) Config ¶
func (c *Conn) Config() *ConnConfig
func (*Conn) IsClientConn ¶
func (*Conn) IsServerConn ¶
func (*Conn) RemoteAddr ¶
type ConnConfig ¶
type ConnConfig struct { Location *url.URL // websocket服务端地址 Origin *url.URL // websocket客户端地址 Protocol []string // 协议 Version int // 协议版本 TlsConfig *tls.Config // wss的配置 Header http.Header // Additional header fields to be sent in WebSocket opening handshake. Dialer *net.Dialer // Dialer used when opening websocket connections. // contains filtered or unexported fields }
type DecodeRequestFunc ¶
type Handler ¶
type Handler struct { DecodeRequest DecodeRequestFunc EncodeResponse EncodeResponseFunc ErrorEncoder ErrorEncoder Endpoint endpoint.Endpoint }
func NewHandler ¶
func NewHandler(decode DecodeRequestFunc, endpoint endpoint.Endpoint) *Handler
NewHandler 实例化处理
type ProtocolError ¶
type ProtocolError struct {
ErrorString string
}
func (*ProtocolError) Error ¶
func (err *ProtocolError) Error() string
type Response ¶
Click to show internal directories.
Click to hide internal directories.