fix: need to hack the condtructor and make a global var as the constructor is getting called twice?

This commit is contained in:
Derrick Hammer 2024-01-30 14:51:23 -05:00
parent 3a49375638
commit 64c3795876
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 14 additions and 8 deletions

View File

@ -11,9 +11,9 @@ import (
"git.lumeweb.com/LumeWeb/portal/storage" "git.lumeweb.com/LumeWeb/portal/storage"
"github.com/spf13/viper" "github.com/spf13/viper"
"go.uber.org/fx" "go.uber.org/fx"
"go.uber.org/fx/fxevent" _"go.uber.org/fx/fxevent"
"go.uber.org/zap" "go.uber.org/zap"
"go.uber.org/zap/zapcore" _"go.uber.org/zap/zapcore"
"net/http" "net/http"
) )
@ -37,13 +37,13 @@ func main() {
fx.Decorate(func() *zap.Logger { fx.Decorate(func() *zap.Logger {
return logger return logger
}), }),/*
fx.WithLogger(func(logger *zap.Logger) fxevent.Logger { fx.WithLogger(func(logger *zap.Logger) fxevent.Logger {
log := &fxevent.ZapLogger{Logger: logger} log := &fxevent.ZapLogger{Logger: logger}
log.UseLogLevel(zapcore.InfoLevel) log.UseLogLevel(zapcore.InfoLevel)
log.UseErrorLevel(zapcore.ErrorLevel) log.UseErrorLevel(zapcore.ErrorLevel)
return log return log
}), }),*/
fx.Invoke(initCheckRequiredConfig), fx.Invoke(initCheckRequiredConfig),
fx.Provide(NewIdentity), fx.Provide(NewIdentity),
db.Module, db.Module,

View File

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