Checkpoint

This commit is contained in:
maze authored and maze committed 2026-10-29 17:29:41 +01:00
1 parent 0295eb1ad2
commit b8a493b93d
138 files changed
+1898 -57607

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
package audio
import (
"fmt"
"sync"
"github.com/sirupsen/logrus"
"go.maze.io/harmon/config"
)
// NotFound signals the player type can not be found.
type NotFound struct {
Type string
}
func (err NotFound) Error() string {
return fmt.Sprintf("audio driver %q can not be found", err.Type)
}
type Opener func(config config.Audio) (Stream, error)
var (
protocols sync.Map
)
func Register(name string, opener Opener) {
logrus.WithField("type", name).Debug("register audio driver")
if _, loaded := protocols.LoadOrStore(name, opener); loaded {
panic(fmt.Sprintf("audio type %q already registered", name))
}
}
func New(config config.Audio) (Stream, error) {
logrus.WithField("type", config.Type).Debug("load audio driver")
opener, ok := protocols.Load(config.Type)
if ok {
return opener.(Opener)(config)
}
return nil, NotFound{config.Type}
}