events

package
v0.0.0-...-06a0142 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: BSD-2-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsStreamWriter

func AsStreamWriter(id int, receiver chan *Message) fasthttp.StreamWriter

func CloseReceiver

func CloseReceiver(id int)

func NewReceiver

func NewReceiver(topics ...Topic) (int, chan *Message)

func SendEvent

func SendEvent(topic Topic, data any)

Types

type ElectionEndedData

type ElectionEndedData struct {
	Election *database.Election `json:"election"`
	Result   string             `json:"result,omitempty"`
}

type Message

type Message struct {
	Topic Topic
	Data  any
}

func (*Message) ToSSE

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

type Topic

type Topic string
const (
	TopicElectionStarted Topic = "election-start"
	TopicElectionEnded   Topic = "election-end"
	TopicVoteReceived    Topic = "vote-received"

	TopicUserElectionStand    Topic = "user-stand"
	TopicUserElectionWithdraw Topic = "user-withdraw"
	TopicUserRestricted       Topic = "user-restrict"
	TopicUserDeleted          Topic = "user-delete"
)

type UserDeletedData

type UserDeletedData struct {
	UserID       string `json:"user"`
	ActingUserID string `json:"actingUserID"`
}

type UserElectionStandData

type UserElectionStandData struct {
	User     *database.User     `json:"user"`
	Election *database.Election `json:"election"`
}

type UserElectionWithdrawData

type UserElectionWithdrawData struct {
	User         *database.User     `json:"user"`
	Election     *database.Election `json:"election"`
	ActingUserID string             `json:"actingUserID,omitempty"`
}

type UserRestrictedData

type UserRestrictedData struct {
	User         *database.User `json:"user"`
	ActingUserID string         `json:"actingUserID"`
}

Jump to

Keyboard shortcuts

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