websocket

package
v0.0.0-...-a287f25 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterChannelCreator

func RegisterChannelCreator(prefix string, fn channelCreator)

func RemoveSubscriberAllChannels

func RemoveSubscriberAllChannels(client *Client)

Types

type Channel

type Channel struct {
	ID      string
	Clients sync.Map

	Subscribe   chan *Client
	Unsubscribe chan string
	Messages    chan *message.WebSocketMessage
}

Channel is a basic type implemented IChannel

func (*Channel) AddMessage

func (c *Channel) AddMessage(msg *message.WebSocketMessage)

func (*Channel) AddSubscriber

func (c *Channel) AddSubscriber(client *Client)

func (*Channel) GetID

func (c *Channel) GetID() string

func (*Channel) MessagesChan

func (c *Channel) MessagesChan() chan *message.WebSocketMessage

func (*Channel) RemoveSubscriber

func (c *Channel) RemoveSubscriber(ID string)

func (*Channel) SubScribeChan

func (c *Channel) SubScribeChan() chan *Client

func (*Channel) UnsubscribeChan

func (c *Channel) UnsubscribeChan() chan string

type Client

type Client struct {
	ID   string
	Conn clientConn

	LoginAddresses map[string]struct{}
	// mu       sync.Mutex
	// for orderbook channel
	Group    int
	Depth    int
	Interval int
	// contains filtered or unexported fields
}

func NewClient

func NewClient(conn clientConn) *Client

func (*Client) AddLoginAddress

func (c *Client) AddLoginAddress(address string)

func (*Client) CheckLogin

func (c *Client) CheckLogin(address string) bool

func (*Client) Close

func (c *Client) Close()

func (*Client) SendMsg

func (c *Client) SendMsg(msg interface{})

type ClientRequest

type ClientRequest struct {
	Type     string   `json:"type"`
	Jwt      string   `json:"jwt"`
	MaiToken string   `json:"maiAuth"`
	Channels []string `json:"channels"`
}

type IChannel

type IChannel interface {
	GetID() string

	// Thread safe calls
	AddSubscriber(*Client)
	RemoveSubscriber(string)
	AddMessage(message *message.WebSocketMessage)

	UnsubscribeChan() chan string
	SubScribeChan() chan *Client
	MessagesChan() chan *message.WebSocketMessage
	// contains filtered or unexported methods
}

type Server

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

func New

func New(ctx context.Context, msgChan chan interface{}) *Server

func (*Server) Start

func (s *Server) Start() error

Jump to

Keyboard shortcuts

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