protocol

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2024 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const (
	SYSTEM_CMD_REMOVE_USER = "remove_user"
)

Variables

View Source
var (
	// ErrorClose 连接关闭的错误信息
	ErrorClose = errors.New("firetower is collapsed")
	// ErrorBlock block错误信息
	ErrorBlock = errors.New("network congestion")
)

Functions

This section is empty.

Types

type Brazier

type Brazier[T any] interface {
	Extinguished(fire *FireInfo[T])
	LightAFire() *FireInfo[T]
}

type Coder

type Coder[T any] interface {
	Decode([]byte, *FireInfo[T]) error
	Encode(msg *FireInfo[T]) []byte
}

type DefaultCoder

type DefaultCoder[T any] struct{}

func (*DefaultCoder[T]) Decode

func (c *DefaultCoder[T]) Decode(data []byte, fire *FireInfo[T]) error

func (*DefaultCoder[T]) Encode

func (c *DefaultCoder[T]) Encode(msg *FireInfo[T]) []byte

type FireInfo

type FireInfo[T any] struct {
	Context     FireLife        `json:"c"`
	MessageType int             `json:"t"`
	Message     TopicMessage[T] `json:"m"`
}

FireInfo 接收的消息结构体

func (*FireInfo[T]) Copy

func (f *FireInfo[T]) Copy() FireInfo[T]

func (*FireInfo[T]) GetContext

func (f *FireInfo[T]) GetContext() FireLife

func (*FireInfo[T]) GetMessage

func (f *FireInfo[T]) GetMessage() TopicMessage[T]

type FireLife

type FireLife struct {
	ID        string            `json:"i"`
	StartTime time.Time         `json:"t"`
	ClientID  string            `json:"c"`
	UserID    string            `json:"u"`
	Source    FireSource        `json:"s"`
	ExtMeta   map[string]string `json:"e,omitempty"`
}

FireLife 客户端推送消息的结构体

func (*FireLife) Reset

func (f *FireLife) Reset(source FireSource, clientID, userID string)

type FireOperation

type FireOperation uint8
const (
	// PublishKey 与前端(客户端约定的推送关键字)
	PublishOperation     FireOperation = 1
	SubscribeOperation   FireOperation = 2
	UnSubscribeOperation FireOperation = 3
	// OfflineTopicByUserIdKey 踢除,将用户某个topic踢下线
	OfflineTopicByUserIdOperation FireOperation = 4
	// OfflineTopicKey 针对某个topic进行踢除
	OfflineTopicOperation FireOperation = 5
	// OfflineUserKey 将某个用户踢下线
	OfflineUserOperation FireOperation = 6
)

func (FireOperation) String

func (o FireOperation) String() string

type FireSource

type FireSource uint8
const (
	SourceClient FireSource = 1
	SourceLogic  FireSource = 2
	SourceSystem FireSource = 3
)

func (FireSource) String

func (s FireSource) String() string

type Logger

type Logger interface {
	Info(string, ...any)
	Debug(string, ...any)
	Error(string, ...any)
}

type Pusher

type Pusher[T any] interface {
	Publish(fire *FireInfo[T]) error
	Receive() chan *FireInfo[T]
}

type ReadOnlyFire

type ReadOnlyFire[T any] interface {
	GetContext() FireLife
	GetMessage() TopicMessage[T]
	Copy() FireInfo[T]
}

type SinglePusher

type SinglePusher[T any] struct {
	// contains filtered or unexported fields
}

func DefaultPusher

func DefaultPusher[T any](b Brazier[T], coder Coder[T], logger Logger) *SinglePusher[T]

func (*SinglePusher[T]) Publish

func (s *SinglePusher[T]) Publish(fire *FireInfo[T]) error

func (*SinglePusher[T]) Receive

func (s *SinglePusher[T]) Receive() chan *FireInfo[T]

type TopicMessage

type TopicMessage[T any] struct {
	Topic string        `json:"topic"`
	Data  T             `json:"data,omitempty"`
	Type  FireOperation `json:"type"`
}

TopicMessage 话题信息结构体

func (*TopicMessage[T]) Json

func (s *TopicMessage[T]) Json() []byte

type TowerInfo

type TowerInfo interface {
	UserID() string
	ClientID() string
}

type WebSocketMessage

type WebSocketMessage struct {
	MessageType int
	Data        []byte
}

Jump to

Keyboard shortcuts

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