Documentation
¶
Overview ¶
Package transport abstracts the WebSocket layer so the dispatcher never touches a concrete websocket library.
Index ¶
- Variables
- type FakeWS
- func (f *FakeWS) Close(StatusCode, string) error
- func (f *FakeWS) Inject(msg []byte)
- func (f *FakeWS) Ping(ctx context.Context) error
- func (f *FakeWS) PingCount() int64
- func (f *FakeWS) Read(ctx context.Context) ([]byte, error)
- func (f *FakeWS) Sent() <-chan []byte
- func (f *FakeWS) SetPingFunc(fn func(context.Context) error)
- func (f *FakeWS) Subprotocol() string
- func (f *FakeWS) Write(ctx context.Context, data []byte) error
- type StatusCode
- type WS
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrFakeClosed = errors.New("transport: fake ws closed")
ErrFakeClosed is returned by a closed FakeWS.
Functions ¶
This section is empty.
Types ¶
type FakeWS ¶
type FakeWS struct {
// contains filtered or unexported fields
}
FakeWS is an in-memory WS for tests. Inbound messages are injected via Inject; outbound writes are observable via Sent.
func (*FakeWS) SetPingFunc ¶ added in v0.1.2
SetPingFunc configures Ping behavior for tests. nil restores the default.
func (*FakeWS) Subprotocol ¶
type StatusCode ¶
type StatusCode int
StatusCode mirrors RFC 6455 close codes (subset used by OCPP).
const ( StatusNormalClosure StatusCode = 1000 StatusGoingAway StatusCode = 1001 StatusProtocolError StatusCode = 1002 StatusInternalError StatusCode = 1011 )
type WS ¶
type WS interface {
// Read blocks until one full text message arrives or ctx is cancelled.
Read(ctx context.Context) ([]byte, error)
// Write sends one text message, respecting ctx for cancellation.
Write(ctx context.Context, data []byte) error
// Ping sends a WebSocket ping and waits for the matching pong.
Ping(ctx context.Context) error
// Close sends a close frame with the given status code and reason.
Close(code StatusCode, reason string) error
// Subprotocol returns the negotiated subprotocol (e.g. "ocpp1.6").
Subprotocol() string
}
WS is a context-native WebSocket connection. All blocking operations accept a context so the dispatcher can cancel reads/writes during connection teardown.
func NewCoderWS ¶
NewCoderWS wraps a coder/websocket connection as a WS.
Click to show internal directories.
Click to hide internal directories.