Documentation
¶
Index ¶
- func SetFrameInterceptor(i FrameInterceptor)
- type ConnInfo
- type FrameInterceptor
- type SafeConn
- func (sc *SafeConn) Close() error
- func (sc *SafeConn) GetConn() *websocket.Conn
- func (sc *SafeConn) ReadJSON(v any) error
- func (sc *SafeConn) ReadMessage() (int, []byte, error)
- func (sc *SafeConn) SetCloseHandler(h func(code int, text string) error)
- func (sc *SafeConn) SetInterceptor(info *ConnInfo, interceptor FrameInterceptor)
- func (sc *SafeConn) SetReadDeadline(t time.Time) error
- func (sc *SafeConn) WriteJSON(v any) error
- func (sc *SafeConn) WriteMessage(messageType int, data []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetFrameInterceptor ¶
func SetFrameInterceptor(i FrameInterceptor)
SetFrameInterceptor wires the plugin hook chain into every WebSocket connection. It must be called once at startup, before connections arrive.
Types ¶
type ConnInfo ¶
ConnInfo describes one WebSocket connection passed to interceptor callbacks. ID matches the owning SafeConn.
type FrameInterceptor ¶
type FrameInterceptor interface {
// OnConnect runs right after the upgrade. A denied connection is closed
// by the caller; plugins bear the consequences of rejecting endpoints
// such as /api/rpc2.
OnConnect(info *ConnInfo) (deny bool, reason string)
// OnMessage inspects one inbound frame; OnSend one outbound frame. They
// return the possibly replaced payload and whether the frame is dropped.
OnMessage(info *ConnInfo, frameType int, data []byte) (newType int, newData []byte, drop bool)
OnSend(info *ConnInfo, frameType int, data []byte) (newType int, newData []byte, drop bool)
// OnClose notifies that the connection ended.
OnClose(info *ConnInfo)
}
FrameInterceptor is the optional hook chain around WebSocket connections and frames. The provider is wired once at startup by internal/app (the plugin manager); a nil interceptor leaves every connection untouched.
func Interceptor ¶
func Interceptor() FrameInterceptor
Interceptor returns the process-wide frame interceptor, or nil when no provider is wired.
type SafeConn ¶
type SafeConn struct {
ID int64
// contains filtered or unexported fields
}
SafeConn wraps a websocket connection with a mutex so concurrent writes cannot interleave frames, and funnels every frame through the optional plugin interceptor when one is attached.
func NewSafeConn ¶
func (*SafeConn) GetConn ¶
GetConn returns the underlying connection. Safe without locking: conn is set once at construction and never reassigned.
func (*SafeConn) SetCloseHandler ¶
SetCloseHandler forwards to the underlying connection (used by the terminal sessions to clean up on close).
func (*SafeConn) SetInterceptor ¶
func (sc *SafeConn) SetInterceptor(info *ConnInfo, interceptor FrameInterceptor)
SetInterceptor attaches the hook provider and the connection identity. It must be called before any frame is read or written.