Documentation
¶
Overview ¶
Package websocket provides reviewed, bounded RFC 6455 server and client integration for Spice applications.
Index ¶
- func Manifest() spicestarter.Manifest
- type AuthenticateFunc
- type ClientConfig
- type Connection
- func (connection *Connection) Close(ctx context.Context, status StatusCode, reason string) error
- func (connection *Connection) Ping(ctx context.Context) error
- func (connection *Connection) Read(ctx context.Context) (MessageType, []byte, error)
- func (connection *Connection) Subprotocol() string
- func (connection *Connection) Write(ctx context.Context, messageType MessageType, payload []byte) error
- type Direction
- type Handler
- type Interaction
- type MessageType
- type Observer
- type Outcome
- type PeerCloseError
- type Result
- type ServerConfig
- type SessionHandler
- type StatusCode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Manifest ¶
func Manifest() spicestarter.Manifest
Manifest returns WebSocket starter compatibility and review metadata.
Types ¶
type AuthenticateFunc ¶
AuthenticateFunc validates one HTTP upgrade request. Returning an error rejects the request with a generic response; the error text is never sent to the peer or an Observer.
type ClientConfig ¶
type ClientConfig struct {
URL string
Header http.Header
Subprotocols []string
TLSConfig *tls.Config
MaxMessageBytes int64
Compression bool
Authorization string
HandshakeTimeout time.Duration
AllowInsecure bool
AllowAnonymous bool
}
ClientConfig defines one explicit outbound WebSocket connection.
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection is one bounded, caller-owned WebSocket connection.
func Dial ¶
func Dial( ctx context.Context, config ClientConfig, observers ...Observer, ) (*Connection, *http.Response, lifecycle.Cleanup, error)
Dial opens one explicit outbound WebSocket connection.
func (*Connection) Close ¶
func (connection *Connection) Close( ctx context.Context, status StatusCode, reason string, ) error
Close performs one close handshake. Cancellation force-closes the socket and returns the caller's cause.
func (*Connection) Ping ¶
func (connection *Connection) Ping(ctx context.Context) error
Ping verifies that the peer responds using the caller-owned context.
func (*Connection) Read ¶
func (connection *Connection) Read( ctx context.Context, ) (MessageType, []byte, error)
Read reads one complete bounded message. Canceling the context closes the underlying connection, matching the native library's explicit contract.
func (*Connection) Subprotocol ¶
func (connection *Connection) Subprotocol() string
Subprotocol returns the negotiated application protocol.
func (*Connection) Write ¶
func (connection *Connection) Write( ctx context.Context, messageType MessageType, payload []byte, ) error
Write sends one complete bounded text or binary message.
type Direction ¶
type Direction string
Direction identifies an inbound or outbound WebSocket session.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is an instance-owned HTTP WebSocket upgrade boundary.
func NewHandler ¶
func NewHandler( config ServerConfig, handle SessionHandler, observers ...Observer, ) (*Handler, error)
NewHandler constructs a WebSocket HTTP handler without starting a listener or goroutine.
type Interaction ¶
Interaction contains payload-free session facts.
type MessageType ¶
type MessageType int
MessageType identifies a text or binary WebSocket message.
const ( // MessageText identifies a UTF-8 text message. MessageText MessageType = 1 // MessageBinary identifies a binary message. MessageBinary MessageType = 2 )
type Observer ¶
type Observer interface {
BeginSession(context.Context, Interaction) func(Result)
}
Observer receives session begin/end facts without message payloads, headers, URLs, peer addresses, or close reasons.
type Outcome ¶
type Outcome string
Outcome identifies a payload-free terminal session state.
const ( // OutcomeNormal identifies an ordinary completed or peer-closed session. OutcomeNormal Outcome = "normal" // OutcomeCanceled identifies caller or lifecycle cancellation. OutcomeCanceled Outcome = "canceled" // OutcomeFailed identifies an application or protocol failure. OutcomeFailed Outcome = "failed" )
type PeerCloseError ¶
type PeerCloseError struct {
Status StatusCode
}
PeerCloseError reports a peer's close status without retaining its potentially sensitive close reason.
func (*PeerCloseError) Error ¶
func (closeError *PeerCloseError) Error() string
Error implements error.
type Result ¶
type Result struct {
Interaction Interaction
Outcome Outcome
Duration time.Duration
}
Result describes one completed session.
type ServerConfig ¶
type ServerConfig struct {
OriginPatterns []string
Subprotocols []string
MaxMessageBytes int64
MaxConnections int
Compression bool
CompressionAt int
CloseTimeout time.Duration
Authenticate AuthenticateFunc
AllowInsecure bool
AllowAnonymous bool
AllowAnyOrigin bool
}
ServerConfig defines one explicit WebSocket HTTP upgrade boundary. TLS is required by default and is terminated by the caller-owned HTTP server.
type SessionHandler ¶
type SessionHandler func(context.Context, *Connection) error
SessionHandler owns one accepted session until it returns.
type StatusCode ¶
type StatusCode int
StatusCode identifies the limited close outcomes applications may emit.
const ( // StatusNormalClosure indicates completed application work. StatusNormalClosure StatusCode = 1000 // StatusGoingAway indicates lifecycle or caller cancellation. StatusGoingAway StatusCode = 1001 // StatusPolicyViolation indicates rejected application input. StatusPolicyViolation StatusCode = 1008 // StatusInternalError indicates an application handler failure. StatusInternalError StatusCode = 1011 )
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
starter-websocket-release
command
Command starter-websocket-release builds deterministic signed library artifacts.
|
Command starter-websocket-release builds deterministic signed library artifacts. |
|
internal
|
|
|
qualitygate
command
Command qualitygate runs starter-websocket's repository-owned cross-platform checks.
|
Command qualitygate runs starter-websocket's repository-owned cross-platform checks. |
|
release
Package release builds deterministic, signed source releases from exact Git commits.
|
Package release builds deterministic, signed source releases from exact Git commits. |