refactor: add concept of a pre-init function that gets called before init
This commit is contained in:
parent
0ac4d318b7
commit
997e362d90
|
@ -14,6 +14,7 @@ func RegisterProtocols() {
|
|||
registry.Register(registry.ProtocolEntry{
|
||||
Key: "s5",
|
||||
Module: s5.ProtocolModule,
|
||||
PreInitFunc: s5.PreInit,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -23,6 +24,9 @@ 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.PreInitFunc != nil {
|
||||
options = append(options, fx.Invoke(entry.PreInitFunc))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ const GroupName = "protocols"
|
|||
|
||||
type Protocol interface {
|
||||
Name() string
|
||||
Init(...any) error
|
||||
Init() error
|
||||
Start(ctx context.Context) error
|
||||
Stop(ctx context.Context) error
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ type Protocol interface {
|
|||
type ProtocolEntry struct {
|
||||
Key string
|
||||
Module fx.Option
|
||||
PreInitFunc interface{}
|
||||
}
|
||||
|
||||
var protocolEntry []ProtocolEntry
|
||||
|
|
Loading…
Reference in New Issue