ws

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TextMessage   int = 1
	BinaryMessage int = 2
	CloseMessage  int = 8
	PingMessage   int = 9
	PongMessage   int = 10
)

Variables

This section is empty.

Functions

func SendError added in v1.0.14

func SendError(socket *websocket.Conn, err error) error

* * SendError * @params socket *websocket.Conn, err error * @return error *

func SendMessage added in v1.0.14

func SendMessage(socket *websocket.Conn, message et.Json) error

* * SendMessage * @params socket *websocket.Conn, message et.Json * @return error *

func Upgrader added in v1.0.12

func Upgrader(w http.ResponseWriter, r *http.Request) (*websocket.Conn, error)

* * Upgrader * @params w http.ResponseWriter, r *http.Request * @return *websocket.Conn, error *

Types

type Channel

type Channel struct {
	Name        string      `json:"name"`
	Type        TypeChannel `json:"type"`
	Subscribers []string    `json:"subscribers"`
	Turn        int         `json:"turn"`
}

type Hub

type Hub struct {
	Channels    map[string]*Channel    `json:"channels"`
	Subscribers map[string]*Subscriber `json:"subscribers"`
	// contains filtered or unexported fields
}

func New added in v1.0.14

func New() *Hub

* * New * @return *Hub *

func (*Hub) Close

func (s *Hub) Close()

* * Close *

func (*Hub) Connect added in v1.0.12

func (s *Hub) Connect(socket *websocket.Conn, ctx context.Context) (*Subscriber, error)

* * Connect * @param socket *websocket.Conn, context.Context * @return *Subscriber, error *

func (*Hub) OnChannel added in v1.0.12

func (s *Hub) OnChannel(fn func(Channel))

* * OnChannel * @param fn func(Channel) *

func (*Hub) OnConnection added in v1.0.12

func (s *Hub) OnConnection(fn func(*Subscriber))

* * OnConnection * @param fn func(*Subscriber) *

func (*Hub) OnDisconnection added in v1.0.12

func (s *Hub) OnDisconnection(fn func(*Subscriber))

* * OnDisconnection * @param fn func(*Subscriber) *

func (*Hub) OnPublish added in v1.0.12

func (s *Hub) OnPublish(fn func(ch Channel, ms Message))

* * OnPublish * @param fn func(ch Channel, ms Message)

func (*Hub) OnRemove added in v1.0.12

func (s *Hub) OnRemove(fn func(string))

* * OnRemove * @param fn func(string) *

func (*Hub) OnSend added in v1.0.12

func (s *Hub) OnSend(fn func(to string, ms Message))

* * OnSend * @param fn func(to string, ms Message)

func (*Hub) Publish

func (s *Hub) Publish(channel string, message Message) ([]string, error)

* * Publish * @param channel string, message Message *

func (*Hub) Queue added in v1.0.12

func (s *Hub) Queue(channel string) *Channel

* * Queue * @param channel string * @return *Channel *

func (*Hub) Remove added in v1.0.12

func (s *Hub) Remove(channel string) error

* * Remove * @param channel string * @return error *

func (*Hub) SendTo added in v1.0.12

func (s *Hub) SendTo(to []string, message Message) ([]string, error)

* * SendTo * @param to []string, message Message *

func (*Hub) SetDebug added in v1.0.12

func (s *Hub) SetDebug(debug bool)

* * SetDebug * @param debug bool *

func (*Hub) Stack

func (s *Hub) Stack(channel string) *Channel

* * Stack * @param channel string * @return *Channel *

func (*Hub) Start

func (s *Hub) Start()

* * Start *

func (*Hub) Subscribe

func (s *Hub) Subscribe(channel string, subscribe string) error

* * Subscribe * @param cache string, subscribe string * @return error *

func (*Hub) Topic added in v1.0.12

func (s *Hub) Topic(channel string) *Channel

* * Topic * @param channel string * @return *Channel *

func (*Hub) Unsubscribe

func (s *Hub) Unsubscribe(cache string, subscribe string) error

* * Unsubscribe * @param cache string, subscribe string * @return error *

type Message

type Message struct {
	Created_at time.Time   `json:"created_at"`
	ID         string      `json:"id"`
	From       et.Json     `json:"from"`
	Channel    string      `json:"channel"`
	To         []string    `json:"to"`
	Ignored    []string    `json:"-"`
	Message    interface{} `json:"message"`
	Verified   bool        `json:"verified"`
}

func DecodeMessage

func DecodeMessage(data []byte) (Message, error)

* * DecodeMessage * @param messageType int, data []byte * @return Message *

func NewMessage

func NewMessage(from et.Json, to []string) Message

* * NewMessage * @param from et.Json, to []string, data et.Json * @return *Message *

func (*Message) Bytes added in v1.0.12

func (s *Message) Bytes() ([]byte, error)

* * Bytes * @return ([]byte, error) *

func (*Message) ToJson

func (s *Message) ToJson() et.Json

* * ToJson * @return et.Json *

func (*Message) ToString

func (s *Message) ToString() string

* * ToString * @return string *

type Outbound added in v1.0.12

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

type Status added in v1.0.12

type Status string
const (
	Pending      Status = "pending"
	Connected    Status = "connected"
	Disconnected Status = "disconnected"
)

type Subscriber

type Subscriber struct {
	Created_at time.Time `json:"created_at"`
	Name       string    `json:"name"`
	Addr       string    `json:"addr"`
	Status     Status    `json:"status"`
	Channels   []string  `json:"channels"`
	// contains filtered or unexported fields
}

type TypeChannel added in v1.0.12

type TypeChannel string
const (
	TpQueue TypeChannel = "Queue"
	TpStack TypeChannel = "Stack"
	TpTopic TypeChannel = "Topic"
)

Jump to

Keyboard shortcuts

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