Documentation ¶
Index ¶
- Constants
- Variables
- func Write(ctx context.Context, c APIConn, api API, id string, payload interface{}) error
- type API
- type APIConn
- type Authenticator
- type Command
- type Conn
- func (ac *Conn) Call(ctx context.Context, api API, payload interface{}) (Command, string, interface{}, error)
- func (ac *Conn) Close() error
- func (ac *Conn) CloseStatus(code websocket.StatusCode, reason string) error
- func (ac *Conn) Connect(ctx context.Context) error
- func (ac *Conn) IsOnline() bool
- func (ac *Conn) Read(ctx context.Context, api API) (Command, string, interface{}, error)
- func (ac *Conn) ReadJSON(ctx context.Context, v any) error
- func (ac *Conn) Write(ctx context.Context, api API, id string, payload interface{}) error
- func (ac *Conn) WriteJSON(ctx context.Context, v any) error
- type Error
- type HandshakeError
- type Header
- type Message
- type PingRequest
- type PingResponse
- type WSConn
Constants ¶
View Source
const ( WSConnectTimeout = 20 * time.Second WSHandshakeTimeout = 15 * time.Second )
View Source
const (
StatusHandshakeErr websocket.StatusCode = 4100 // XXX can we just hijack 4100?
)
Variables ¶
View Source
var ErrInvalidCommand = errors.New("invalid command")
View Source
var PublicKeyAuthError = websocket.CloseError{ Code: StatusHandshakeErr, Reason: HandshakeError("invalid public key").Error(), }
Functions ¶
Types ¶
type APIConn ¶
type APIConn interface { ReadJSON(ctx context.Context, v any) error WriteJSON(ctx context.Context, v any) error }
APIConn provides an API connection.
type Authenticator ¶
type Authenticator interface { HandshakeClient(ctx context.Context, ac APIConn) error HandshakeServer(ctx context.Context, ac APIConn) error }
Authenticator implements authentication between a client and a server.
type Conn ¶
Conn is a client side connection.
func NewConn ¶
func NewConn(urlStr string, authenticator Authenticator) (*Conn, error)
NewConn returns a client side connection object.
func (*Conn) Call ¶
func (ac *Conn) Call(ctx context.Context, api API, payload interface{}) (Command, string, interface{}, error)
Call is a blocking call that returns the command, id and unmarshaled payload.
func (*Conn) CloseStatus ¶
func (ac *Conn) CloseStatus(code websocket.StatusCode, reason string) error
CloseStatus close the connection with the provided StatusCode.
type Error ¶
type Error struct { Timestamp int64 `json:"timestamp"` Trace string `json:"trace"` Message string `json:"error"` }
Error is a protocol Error type that can be used for additional error context. It embeds an 8 byte number that can be used to trace calls on both the client and server side.
type HandshakeError ¶
type HandshakeError string
func (HandshakeError) Error ¶
func (he HandshakeError) Error() string
func (HandshakeError) Is ¶
func (he HandshakeError) Is(target error) bool
type Header ¶
type Header struct { Command Command `json:"command"` // Command to execute ID string `json:"id,omitempty"` // Command identifier }
Header prefixes all websocket commands.
type Message ¶
type Message struct { Header Header `json:"header"` Payload json.RawMessage `json:"payload"` }
Message represents a websocket message.
type PingRequest ¶
type PingRequest struct {
Timestamp int64 `json:"timestamp"` // Local timestamp
}
Ping
type PingResponse ¶
type PingResponse struct { OriginTimestamp int64 `json:"origintimestamp"` // Timestamp from origin Timestamp int64 `json:"timestamp"` // Local timestamp }
PingResponse
type WSConn ¶
type WSConn struct {
// contains filtered or unexported fields
}
func (*WSConn) CloseStatus ¶
func (wsc *WSConn) CloseStatus(code websocket.StatusCode, reason string) error
Click to show internal directories.
Click to hide internal directories.