webws

package
v2.0.0-...-4d7e8e0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2025 License: BSD-2-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

This section is empty.

Types

type Message

type Message struct {
	To       string   `json:"to"`
	Response Response `json:"response"`
}

func NewMessage

func NewMessage(to string, tag string, body any) Message

func (*Message) Marshal

func (m *Message) Marshal() ([]byte, error)

func (*Message) ResponseBytes

func (m *Message) ResponseBytes() []byte

func (*Message) Sign

func (m *Message) Sign() string

type MessageTagTpl

type MessageTagTpl string

websocket message tags

const (
	MsgDepthTpl       MessageTagTpl = "depth.{symbol}"
	MsgTradeTpl       MessageTagTpl = "trade.{symbol}"
	MsgLatestPriceTpl MessageTagTpl = "price.{symbol}"
	MsgMarketKLineTpl MessageTagTpl = "kline.{period}.{symbol}"
	MsgMarket24HTpl   MessageTagTpl = "market.24h.{symbol}"
	MsgOrderCancelTpl MessageTagTpl = "order.cancel.{symbol}"
	MsgNewOrderTpl    MessageTagTpl = "order.new.{symbol}"
	MsgTokenTpl       MessageTagTpl = "token.{token}"
	MsgUserTpl        MessageTagTpl = "_user.{user_id}" //特殊的类型,通过后端程序设置的属性
)

func (MessageTagTpl) Format

func (w MessageTagTpl) Format(data map[string]string) string

type RecviceTag

type RecviceTag struct {
	Subscribe   []string `json:"subscribe,omitempty"`
	Unsubscribe []string `json:"unsubscribe,omitempty"`
}

type Response

type Response struct {
	Type string `json:"type,omitempty"`
	Body any    `json:"body,omitempty"`
}

type WsManager

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

func NewWsManager

func NewWsManager(logger *zap.Logger, broker broker.Broker) *WsManager

func (*WsManager) Broadcast

func (m *WsManager) Broadcast(ctx context.Context, _type string, body any) error

func (*WsManager) Listen

func (m *WsManager) Listen(writer http.ResponseWriter, req *http.Request, responseHeader http.Header)

func (*WsManager) SendTo

func (m *WsManager) SendTo(ctx context.Context, uid string, _type string, body any) error

单发消息给某一个用户 SendTo("1001", "order.new.usdjpy", "") SendTo("1001", "order.cancel.usdjpy", "")

func (*WsManager) SetDebug

func (m *WsManager) SetDebug(v bool)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳