Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Created September 25, 2022 11:39
Show Gist options
  • Save percybolmer/e2f82524a7cd86ade5c75cd9298fa638 to your computer and use it in GitHub Desktop.
Save percybolmer/e2f82524a7cd86ade5c75cd9298fa638 to your computer and use it in GitHub Desktop.
// Manager is used to hold references to all Clients Registered, and Broadcasting etc
type Manager struct {
clients ClientList
// Using a syncMutex here to be able to lcok state before editing clients
// Could also use Channels to block
sync.RWMutex
// handlers are functions that are used to handle Events
handlers map[string]EventHandler
// otps is a map of allowed OTP to accept connections from
otps RetentionMap
}
// NewManager is used to initalize all the values inside the manager
func NewManager(ctx context.Context) *Manager {
m := &Manager{
clients: make(ClientList),
handlers: make(map[string]EventHandler),
// Create a new retentionMap that removes Otps older than 5 seconds
otps: NewRetentionMap(ctx, 5*time.Second),
}
m.setupEventHandlers()
return m
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment