initial commit

This commit is contained in:
2025-10-15 18:44:51 -05:00
commit 084284370c
9 changed files with 347 additions and 0 deletions

44
protocol.go Normal file
View File

@@ -0,0 +1,44 @@
package showbridge
import (
"context"
"fmt"
"sync"
)
type Protocol interface {
Run(context.Context) error
}
type ProtocolConfig struct {
Type string `json:"type"`
Params map[string]any `json:"params"`
}
type ProtocolRegistration struct {
Type string `json:"type"`
New func(map[string]any) (Protocol, error)
}
func RegisterProtocol(proto ProtocolRegistration) {
if proto.Type == "" {
panic("protocol type is missing")
}
if proto.New == nil {
panic("missing ProtocolInfo.New")
}
protocolRegistryMu.Lock()
defer protocolRegistryMu.Unlock()
if _, ok := protocolRegistry[string(proto.Type)]; ok {
panic(fmt.Sprintf("protocol already registered: %s", proto.Type))
}
protocolRegistry[string(proto.Type)] = proto
}
var (
protocolRegistryMu sync.RWMutex
protocolRegistry = make(map[string]ProtocolRegistration)
)