ws

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const HeaderClientId = "x-backstream-client-id"

Variables

View Source
var ErrConnectionClosed = errors.New("connection closed")

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(parent context.Context, urlStr string, handler EventHandler, codec Codec[*message.Message], opts ...ClientOption) *Client

func (*Client) GetConn

func (c *Client) GetConn() (*Conn, error)

func (*Client) Start

func (c *Client) Start()

type ClientOption

type ClientOption func(*Client)

func WithClientID

func WithClientID(clientID string) ClientOption

func WithClientLogger

func WithClientLogger(logger *slog.Logger) ClientOption

func WithClientTLSConfigFunc added in v0.0.2

func WithClientTLSConfigFunc(tlsConfigFunc func() *tls.Config) ClientOption

type Codec

type Codec[T proto.Message] interface {
	Encode(t T) ([]byte, error)
	Decode(data []byte, t T) error
	// IsBinary determines is message is text or binary data message.
	IsBinary() bool
}

func NewJsonCodec

func NewJsonCodec[T proto.Message]() Codec[T]

func NewProtoCodec

func NewProtoCodec[T proto.Message]() Codec[T]

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

func (*Conn) Close

func (c *Conn) Close()

func (*Conn) Notify

func (c *Conn) Notify(ctx context.Context, input []byte) error

func (*Conn) Send

func (c *Conn) Send(ctx context.Context, input []byte) ([]byte, error)

type EventHandler

type EventHandler interface {
	HandleRequest(ctx context.Context, event []byte) ([]byte, error)
	HandleNotify(ctx context.Context, event []byte) error
}

type JsonCodec

type JsonCodec[T proto.Message] struct {
}

func (JsonCodec[T]) Decode

func (c JsonCodec[T]) Decode(data []byte, t T) error

func (JsonCodec[T]) Encode

func (c JsonCodec[T]) Encode(v T) ([]byte, error)

func (JsonCodec[T]) IsBinary

func (c JsonCodec[T]) IsBinary() bool

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

func NewPool

func NewPool() *Pool

func (*Pool) GetConn

func (m *Pool) GetConn() *Conn

func (*Pool) GetConnByID

func (m *Pool) GetConnByID(id string) *Conn

func (*Pool) GetConnsByID

func (m *Pool) GetConnsByID(id string) (result []*Conn)

func (*Pool) Size

func (m *Pool) Size() int

type ProtoCodec

type ProtoCodec[T proto.Message] struct {
}

func (ProtoCodec[T]) Decode

func (c ProtoCodec[T]) Decode(data []byte, t T) error

func (ProtoCodec[T]) Encode

func (c ProtoCodec[T]) Encode(v T) ([]byte, error)

func (ProtoCodec[T]) IsBinary

func (c ProtoCodec[T]) IsBinary() bool

type ProxyHandler

type ProxyHandler interface {
	EventHandler
	ProxyRequest(conn *Conn, w http.ResponseWriter, r *http.Request) error
}

type Serve

type Serve struct {
	// contains filtered or unexported fields
}

func NewServe

func NewServe(parent context.Context, handler ProxyHandler, codec Codec[*message.Message], opts ...ServeOption) *Serve

func (*Serve) GetConnByID

func (s *Serve) GetConnByID(id string) *Conn

func (*Serve) GetConnsByID

func (s *Serve) GetConnsByID(id string) []*Conn

func (*Serve) HandleProxy

func (s *Serve) HandleProxy(w http.ResponseWriter, r *http.Request)

func (*Serve) HandleProxyWithRetry

func (s *Serve) HandleProxyWithRetry(w http.ResponseWriter, r *http.Request)

func (*Serve) HandleWS

func (s *Serve) HandleWS(w http.ResponseWriter, r *http.Request)

type ServeOption

type ServeOption func(*Serve)

func WithRequireClientId

func WithRequireClientId(b bool) ServeOption

func WithServeLogger

func WithServeLogger(logger *slog.Logger) ServeOption

Jump to

Keyboard shortcuts

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