websocket

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MethodSubscribe   = "subscribe"
	MethodUnsubscribe = "unsubscribe"
)

methods

View Source
const (
	ChannelHead = "head"
	ChannelTx   = "tx"
)

channels

Variables

View Source
var (
	ErrUnknownMethod     = errors.New("unknown method")
	ErrUnknownChannel    = errors.New("unknown channel")
	ErrUnavailableFilter = errors.New("unknown filter value")
)

Functions

This section is empty.

Types

type Channel

type Channel[I, M any] struct {
	// contains filtered or unexported fields
}

func NewChannel

func NewChannel[I, M any](processor processor[I, M], filters Filterable[M]) *Channel[I, M]

func (*Channel[I, M]) AddClient

func (channel *Channel[I, M]) AddClient(c client)

func (*Channel[I, M]) RemoveClient

func (channel *Channel[I, M]) RemoveClient(id uint64)

type Client

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

func (*Client) ApplyFilters

func (c *Client) ApplyFilters(msg Subscribe) error

func (*Client) Close

func (c *Client) Close() error

func (*Client) DetachFilters

func (c *Client) DetachFilters(msg Unsubscribe) error

func (*Client) Filters

func (c *Client) Filters() *Filters

func (*Client) Id

func (c *Client) Id() uint64

func (*Client) Notify

func (c *Client) Notify(msg any)

func (*Client) ReadMessages

func (c *Client) ReadMessages(ctx context.Context, ws *websocket.Conn, sub *Client, log echo.Logger)

func (*Client) WriteMessages

func (c *Client) WriteMessages(ctx context.Context, ws *websocket.Conn, log echo.Logger)

type Filterable

type Filterable[M any] interface {
	Filter(c client, msg M) bool
}

type Filters

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

type HeadFilter

type HeadFilter struct{}

func (HeadFilter) Filter

func (hf HeadFilter) Filter(c client, msg *responses.Block) bool

type Manager

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

func NewManager

func NewManager(observer *bus.Observer) *Manager

func (*Manager) AddClientToChannel

func (manager *Manager) AddClientToChannel(channel string, client *Client)

func (*Manager) Close

func (manager *Manager) Close() error

func (*Manager) Handle

func (manager *Manager) Handle(c echo.Context) error

Handle godoc

@Summary				Websocket API
@Description.markdown	websocket
@Tags					websocket
@ID						websocket
@Produce				json
@Router					/v1/ws [get]

func (*Manager) RemoveClientFromChannel

func (manager *Manager) RemoveClientFromChannel(channel string, client *Client)

func (*Manager) Start

func (manager *Manager) Start(ctx context.Context)

type Message

type Message struct {
	Method string          `json:"method" validate:"required,oneof=subscribe,unsubscribe"`
	Body   json.RawMessage `json:"body"   validate:"required"`
}

type Subscribe

type Subscribe struct {
	Channel string          `json:"channel" validate:"required,oneof=head tx"`
	Filters json.RawMessage `json:"filters" validate:"required"`
}

type TransactionFilters

type TransactionFilters struct {
	Status   []string `json:"status,omitempty"`
	Messages []string `json:"msg_type,omitempty"`
}

type TxFilter

type TxFilter struct{}

func (TxFilter) Filter

func (hf TxFilter) Filter(c client, msg *responses.Tx) bool

type Unsubscribe

type Unsubscribe struct {
	Channel string `json:"channel" validate:"required,oneof=head tx"`
}

Jump to

Keyboard shortcuts

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