diff --git a/protocols/protocols.go b/protocols/protocols.go index 2191274..81b7d9f 100644 --- a/protocols/protocols.go +++ b/protocols/protocols.go @@ -2,6 +2,7 @@ package protocols import ( "context" + "git.lumeweb.com/LumeWeb/portal/protocols/registry" "git.lumeweb.com/LumeWeb/portal/protocols/s5" "github.com/samber/lo" @@ -11,9 +12,8 @@ import ( func RegisterProtocols() { registry.Register(registry.ProtocolEntry{ - Key: "s5", - Module: s5.ProtocolModule, - InitFunc: s5.InitProtocol, + Key: "s5", + Module: s5.ProtocolModule, }) } @@ -23,12 +23,20 @@ func BuildProtocols(config *viper.Viper) fx.Option { for _, entry := range registry.GetRegistry() { if lo.Contains(enabledProtocols, entry.Key) { options = append(options, entry.Module) - if entry.InitFunc != nil { - options = append(options, fx.Invoke(entry.InitFunc)) - } } } + options = append(options, fx.Invoke(func(protocols []registry.Protocol) error { + for _, protocol := range protocols { + err := protocol.Init() + if err != nil { + return err + } + } + + return nil + })) + return fx.Module("protocols", fx.Options(options...)) } diff --git a/protocols/registry/registry.go b/protocols/registry/registry.go index 823a171..223af97 100644 --- a/protocols/registry/registry.go +++ b/protocols/registry/registry.go @@ -2,6 +2,7 @@ package registry import ( "context" + "go.uber.org/fx" ) @@ -15,9 +16,8 @@ type Protocol interface { } type ProtocolEntry struct { - Key string - Module fx.Option - InitFunc interface{} + Key string + Module fx.Option } var protocolEntry []ProtocolEntry diff --git a/protocols/s5/s5.go b/protocols/s5/s5.go index c04d02f..4bc9473 100644 --- a/protocols/s5/s5.go +++ b/protocols/s5/s5.go @@ -162,9 +162,6 @@ func NewS5ProviderStore(params S5ProviderStoreParams) *S5ProviderStore { } } -func InitProtocol(s5 *S5Protocol, node *s5node.Node, store *S5ProviderStore) error { - return s5.Init(node, store) -} func (s *S5Protocol) Init(args ...any) error { if node, ok := args[0].(*s5node.Node); !ok { s.logger.Fatal("Node is not a s5 node")