This commit is contained in:
parent
9c78ea2d48
commit
7c684af8c3
79 changed files with 3594 additions and 3257 deletions
49
internal/platform/registry.go
Normal file
49
internal/platform/registry.go
Normal file
|
@ -0,0 +1,49 @@
|
|||
package platform
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"git.nakama.town/fmartingr/butterrobot/internal/model"
|
||||
)
|
||||
|
||||
var (
|
||||
// platforms holds all registered chat platforms
|
||||
platforms = make(map[string]model.Platform)
|
||||
|
||||
// platformsMu protects the platforms map
|
||||
platformsMu sync.RWMutex
|
||||
)
|
||||
|
||||
// Register registers a platform with the given ID
|
||||
func Register(id string, platform model.Platform) {
|
||||
platformsMu.Lock()
|
||||
defer platformsMu.Unlock()
|
||||
platforms[id] = platform
|
||||
}
|
||||
|
||||
// Get returns a platform by ID
|
||||
func Get(id string) (model.Platform, error) {
|
||||
platformsMu.RLock()
|
||||
defer platformsMu.RUnlock()
|
||||
|
||||
platform, exists := platforms[id]
|
||||
if !exists {
|
||||
return nil, model.ErrPlatformNotFound
|
||||
}
|
||||
|
||||
return platform, nil
|
||||
}
|
||||
|
||||
// GetAvailablePlatforms returns all registered platforms
|
||||
func GetAvailablePlatforms() map[string]model.Platform {
|
||||
platformsMu.RLock()
|
||||
defer platformsMu.RUnlock()
|
||||
|
||||
// Create a copy to avoid race conditions
|
||||
result := make(map[string]model.Platform, len(platforms))
|
||||
for id, platform := range platforms {
|
||||
result[id] = platform
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue