Created
September 25, 2022 11:39
-
-
Save percybolmer/e2f82524a7cd86ade5c75cd9298fa638 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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