fix: no need for singleton hack, use Replace not Decorate

This commit is contained in:
Derrick Hammer 2024-01-31 22:51:51 -05:00
parent 9a87004f31
commit 95cfa393b4
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 5 additions and 11 deletions

View File

@ -21,9 +21,8 @@ import (
)
var (
_ s5storage.ProviderStore = (*S5ProviderStore)(nil)
_ registry.Protocol = (*S5Protocol)(nil)
instance *S5ProtocolResult
_ s5storage.ProviderStore = (*S5ProviderStore)(nil)
_ registry.Protocol = (*S5Protocol)(nil)
)
type S5Protocol struct {
@ -54,7 +53,7 @@ type S5ProtocolResult struct {
var ProtocolModule = fx.Module("s5_api",
fx.Provide(NewS5Protocol),
fx.Provide(NewS5ProviderStore),
fx.Decorate(func(cfg *s5config.NodeConfig) *zap.Logger {
fx.Replace(func(cfg *s5config.NodeConfig) *zap.Logger {
return cfg.Logger
}),
s5fx.Module,
@ -63,9 +62,6 @@ var ProtocolModule = fx.Module("s5_api",
func NewS5Protocol(
params S5ProtocolParams,
) (S5ProtocolResult, error) {
if instance != nil {
return *instance, nil
}
proto := &S5Protocol{
config: params.Config,
logger: params.Logger,
@ -78,14 +74,12 @@ func NewS5Protocol(
return S5ProtocolResult{}, err
}
instance = &S5ProtocolResult{
return S5ProtocolResult{
Protocol: proto,
S5Protocol: proto,
S5NodeConfig: cfg,
Db: cfg.DB,
}
return *instance, nil
}, nil
}
func ConfigureS5Protocol(params S5ProtocolParams) (*s5config.NodeConfig, error) {