ws

package
v0.0.85 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorToHttpCode

func ErrorToHttpCode(err error) int

func SendJsonResponse

func SendJsonResponse(writer http.ResponseWriter, resp interface{}, err error)

func WSConnJSONReaderWriter added in v0.0.59

func WSConnJSONReaderWriter(conn *websocket.Conn) (reader *conc.Reader[gut.StringMap], writer *conc.Writer[conc.Message[gut.StringMap]])

func WSConnWriteError

func WSConnWriteError(wsConn *websocket.Conn, err error) error

func WSConnWriteMessage

func WSConnWriteMessage(wsConn *websocket.Conn, msg interface{}) error

func WSHandleConn added in v0.0.60

func WSHandleConn[I any, S WSConn[I]](conn *websocket.Conn, ctx S, config *WSConnConfig)

func WSServe added in v0.0.60

func WSServe[I any, S WSConn[I]](h WSHandler[I, S], config *WSConnConfig) http.HandlerFunc

Types

type BiDirStreamConfig added in v0.0.70

type BiDirStreamConfig struct {
	PingPeriod time.Duration
	PongPeriod time.Duration
}

func DefaultBiDirStreamConfig added in v0.0.70

func DefaultBiDirStreamConfig() *BiDirStreamConfig

type BiDirStreamConn added in v0.0.70

type BiDirStreamConn[I any] interface {
	/**
	 * Called to send the next ping message.
	 */
	SendPing() error

	// Optional Name of the connection
	Name() string

	// Optional connection id
	ConnId() string

	/**
	 * Called to handle the next message from the input stream on the ws conn.
	 */
	HandleMessage(msg I) error

	/**
	 * Called to handle or suppress an error
	 */
	OnError(err error) error

	/**
	 * Called when the connection closes.
	 */
	OnClose()
	OnTimeout() bool
}

type JSONConn added in v0.0.62

type JSONConn struct {
	Writer    *conc.Writer[conc.Message[any]]
	NameStr   string
	ConnIdStr string
	PingId    int64
}

func (*JSONConn) ConnId added in v0.0.65

func (j *JSONConn) ConnId() string

func (*JSONConn) DebugInfo added in v0.0.80

func (j *JSONConn) DebugInfo() any

func (*JSONConn) HandleMessage added in v0.0.62

func (j *JSONConn) HandleMessage(msg any) error

*

  • Called to handle the next message from the input stream on the ws conn.

func (*JSONConn) Name added in v0.0.65

func (j *JSONConn) Name() string

func (*JSONConn) OnClose added in v0.0.62

func (j *JSONConn) OnClose()

*

  • Called when the connection closes.

func (*JSONConn) OnError added in v0.0.62

func (j *JSONConn) OnError(err error) error

func (*JSONConn) OnStart added in v0.0.62

func (j *JSONConn) OnStart(conn *websocket.Conn) error

func (*JSONConn) OnTimeout added in v0.0.62

func (j *JSONConn) OnTimeout() bool

func (*JSONConn) ReadMessage added in v0.0.62

func (j *JSONConn) ReadMessage(conn *websocket.Conn) (out any, err error)

*

  • Reads the next message from the ws conn.

func (*JSONConn) SendPing added in v0.0.62

func (j *JSONConn) SendPing() error

*

  • Called to send the next ping message.

type JSONHandler added in v0.0.60

type JSONHandler struct {
}

func (*JSONHandler) Validate added in v0.0.60

func (j *JSONHandler) Validate(w http.ResponseWriter, r *http.Request) (out WSConn[any], isValid bool)

type WSConn added in v0.0.55

type WSConn[I any] interface {
	BiDirStreamConn[I]
	/**
	 * Reads the next message from the ws conn.
	 */
	ReadMessage(w *websocket.Conn) (I, error)
	/**
	 * On created.
	 */
	OnStart(conn *websocket.Conn) error
}

type WSConnConfig added in v0.0.60

type WSConnConfig struct {
	*BiDirStreamConfig
	Upgrader websocket.Upgrader
}

func DefaultWSConnConfig added in v0.0.60

func DefaultWSConnConfig() *WSConnConfig

type WSHandler added in v0.0.60

type WSHandler[I any, S WSConn[I]] interface {
	/**
	 * Called to validate an http request to see if it is upgradeable to a ws conn
	 */
	Validate(w http.ResponseWriter, r *http.Request) (S, bool)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL