portal/protocols/registry/registry.go

45 lines
770 B
Go
Raw Permalink Normal View History

package registry
import (
"context"
"git.lumeweb.com/LumeWeb/portal/config"
"go.uber.org/fx"
)
const GroupName = "protocols"
type Protocol interface {
Name() string
2024-02-27 08:35:43 +00:00
Init(ctx context.Context) error
Start(ctx context.Context) error
Stop(ctx context.Context) error
Config() config.ProtocolConfig
}
type ProtocolEntry struct {
Key string
Module fx.Option
PreInitFunc interface{}
}
var protocolEntry []ProtocolEntry
func Register(entry ProtocolEntry) {
protocolEntry = append(protocolEntry, entry)
}
func GetRegistry() []ProtocolEntry {
return protocolEntry
}
func FindProtocolByName(name string, protocols []Protocol) Protocol {
for _, protocol := range protocols {
if protocol.Name() == name {
return protocol
}
}
return nil
}