rmessage

package module
v0.0.0-...-4884a6a Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

README

自定义的消息队列协议

基于websocket

在连接后,客户端的第一个包应该为认证请求,payload为认证信息 认证请求type为0, topic为auth,message中为认证消息

除了认证请求外,有以下几种请求

1.向特定topic发送消息

{ "type" : 1, "topic" : "topic", "message" : }

Documentation

Index

Constants

View Source
const (
	MessageTypeAuth      = 0
	MessageTypeBroadcast = 1
	MessageTypeAssigned  = 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthFunc

type AuthFunc func(user *User, message *Message) bool

type Events

type Events struct {
	OnAuth    AuthFunc
	OnMessage MessageFunc
}

type Message

type Message struct {
	Payload *fastjson.Value `json:"payload"`
	Type    int             `json:"type"`
	Topic   string          `json:"topic"`
}

type MessageFunc

type MessageFunc func(user *User, message *Message)

type Server

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

func New

func New() *Server

func (*Server) AddTopic

func (s *Server) AddTopic(topicName string, defaultTopic bool) error

func (*Server) BroadCast

func (s *Server) BroadCast(topic string, payload interface{}) error

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(addr string) error

func (*Server) ListenAndServeTLS

func (s *Server) ListenAndServeTLS(addr string, certFile string, keyFile string) error

func (*Server) ListenAndServeTLSEmbed

func (s *Server) ListenAndServeTLSEmbed(addr string, cert []byte, key []byte) error

func (*Server) SendToUser

func (s *Server) SendToUser(topic string, payload interface{}, userID int64) error

type User

type User struct {
	ID          int64
	ConnectTime time.Time

	SubcribedTopics []string
	Online          bool
	// contains filtered or unexported fields
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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