broadcast

package
v0.0.0-...-aba8388 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode[T any](data []byte) (*T, *errors.Error)

func Encode

func Encode(data interface{}) ([]byte, *errors.Error)

func MessageScan

func MessageScan[T any](msg *Message) (*T, *errors.Error)

Types

type Data

type Data struct {
	Peer      Peer     `bson:"peer" json:"peer"`
	VN        string   `bson:"vn" json:"vn"`
	Scope     string   `bson:"scope" json:"scope"`
	Data      string   `bson:"data" json:"data"`
	Timestamp int64    `bson:"timestamp" json:"timestamp"`
	Tag       []string `bson:"tag,omitempty" json:"tag,omitempty"`
}

func DataOfBytes

func DataOfBytes(payload []byte) (*Data, *errors.Error)

func (*Data) ToBytes

func (data *Data) ToBytes() ([]byte, *errors.Error)

func (*Data) WithData

func (data *Data) WithData(d interface{}) *errors.Error

type Listener

type Listener interface {
	GetCode() string
	Care(ctx context.Context, msg *Message) bool
	Deal(ctx context.Context, msg *Message) *errors.Error
}

type MQ

type MQ struct {
	Topic string
	// contains filtered or unexported fields
}

func NewMQ

func NewMQ(topic string) (*MQ, *errors.Error)

func (*MQ) Publish

func (mq *MQ) Publish(msgData Data) *errors.Error

func (*MQ) RegisterListener

func (mq *MQ) RegisterListener(listener Listener)

func (*MQ) StartListening

func (mq *MQ) StartListening()

type Message

type Message struct {
	Peer      Peer     `bson:"peer" json:"peer"`
	Topic     string   `bson:"topic" json:"topic"`
	VN        string   `bson:"vn" json:"vn"`
	Scope     string   `bson:"scope" json:"scope"`
	ID        string   `bson:"id" json:"id"`
	Data      []byte   `bson:"data" json:"data"`
	Timestamp int64    `bson:"timestamp" json:"timestamp"`
	Tag       []string `bson:"tag,omitempty" json:"tag,omitempty"`
}

func MessageOf

func MessageOf(pbMsg *pubsub.Message) (*Message, *errors.Error)

func (*Message) Summary

func (msg *Message) Summary() string

type Peer

type Peer struct {
	ID   string     `bson:"id" json:"id"`
	Mode point.Mode `bson:"mode" json:"mode"`
}

Jump to

Keyboard shortcuts

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