2024-01-12 00:11:53 +00:00
|
|
|
package main
|
|
|
|
|
2024-01-28 07:20:59 +00:00
|
|
|
import (
|
2024-01-28 08:55:09 +00:00
|
|
|
"git.lumeweb.com/LumeWeb/portal/account"
|
2024-01-28 07:20:59 +00:00
|
|
|
"git.lumeweb.com/LumeWeb/portal/api"
|
|
|
|
_config "git.lumeweb.com/LumeWeb/portal/config"
|
|
|
|
"git.lumeweb.com/LumeWeb/portal/cron"
|
|
|
|
"git.lumeweb.com/LumeWeb/portal/db"
|
|
|
|
_logger "git.lumeweb.com/LumeWeb/portal/logger"
|
|
|
|
"git.lumeweb.com/LumeWeb/portal/protocols"
|
2024-02-01 02:27:38 +00:00
|
|
|
"git.lumeweb.com/LumeWeb/portal/renter"
|
2024-01-28 07:20:59 +00:00
|
|
|
"git.lumeweb.com/LumeWeb/portal/storage"
|
2024-01-30 22:45:36 +00:00
|
|
|
flag "github.com/spf13/pflag"
|
2024-01-28 07:20:59 +00:00
|
|
|
"github.com/spf13/viper"
|
|
|
|
"go.uber.org/fx"
|
2024-01-30 22:45:36 +00:00
|
|
|
"go.uber.org/fx/fxevent"
|
|
|
|
_ "go.uber.org/fx/fxevent"
|
2024-01-28 07:20:59 +00:00
|
|
|
"go.uber.org/zap"
|
2024-01-30 22:45:36 +00:00
|
|
|
"go.uber.org/zap/zapcore"
|
|
|
|
_ "go.uber.org/zap/zapcore"
|
2024-01-28 07:20:59 +00:00
|
|
|
"net/http"
|
|
|
|
)
|
2024-01-12 00:11:53 +00:00
|
|
|
|
|
|
|
func main() {
|
2024-01-28 07:20:59 +00:00
|
|
|
|
|
|
|
logger := _logger.NewLogger()
|
|
|
|
config, err := _config.NewConfig(logger)
|
|
|
|
|
2024-01-12 00:11:53 +00:00
|
|
|
if err != nil {
|
2024-01-28 07:20:59 +00:00
|
|
|
logger.Fatal("Failed to load config", zap.Error(err))
|
2024-01-12 00:11:53 +00:00
|
|
|
}
|
2024-01-28 07:20:59 +00:00
|
|
|
|
2024-01-30 22:45:36 +00:00
|
|
|
var fxDebug bool
|
|
|
|
|
|
|
|
flag.BoolVar(&fxDebug, "fx-debug", false, "Enable fx framework debug logging")
|
|
|
|
flag.Parse()
|
|
|
|
|
2024-01-28 07:20:59 +00:00
|
|
|
protocols.RegisterProtocols()
|
|
|
|
api.RegisterApis()
|
|
|
|
|
2024-01-30 22:45:36 +00:00
|
|
|
var fxLogger fx.Option
|
|
|
|
|
|
|
|
fxLogger = fx.WithLogger(func(logger *zap.Logger) fxevent.Logger {
|
|
|
|
log := &fxevent.ZapLogger{Logger: logger}
|
|
|
|
log.UseLogLevel(zapcore.InfoLevel)
|
|
|
|
log.UseErrorLevel(zapcore.ErrorLevel)
|
|
|
|
return log
|
|
|
|
})
|
|
|
|
|
|
|
|
if fxDebug {
|
|
|
|
fxLogger = fx.Options()
|
|
|
|
}
|
|
|
|
|
2024-01-28 07:20:59 +00:00
|
|
|
fx.New(
|
|
|
|
fx.Provide(_logger.NewFallbackLogger),
|
|
|
|
fx.Provide(func() *viper.Viper {
|
|
|
|
return config
|
|
|
|
}),
|
|
|
|
|
|
|
|
fx.Decorate(func() *zap.Logger {
|
|
|
|
return logger
|
2024-01-30 22:45:36 +00:00
|
|
|
}),
|
|
|
|
fxLogger,
|
2024-01-28 07:20:59 +00:00
|
|
|
fx.Invoke(initCheckRequiredConfig),
|
|
|
|
fx.Provide(NewIdentity),
|
|
|
|
db.Module,
|
2024-02-01 02:27:38 +00:00
|
|
|
renter.Module,
|
2024-01-28 07:20:59 +00:00
|
|
|
storage.Module,
|
|
|
|
cron.Module,
|
2024-01-28 08:55:09 +00:00
|
|
|
account.Module,
|
2024-01-28 07:20:59 +00:00
|
|
|
protocols.BuildProtocols(config),
|
|
|
|
api.BuildApis(config),
|
|
|
|
fx.Provide(api.NewCasbin),
|
2024-01-28 08:29:52 +00:00
|
|
|
fx.Invoke(protocols.SetupLifecycles),
|
|
|
|
fx.Invoke(api.SetupLifecycles),
|
2024-01-28 10:07:13 +00:00
|
|
|
fx.Provide(NewServer),
|
2024-01-28 10:08:19 +00:00
|
|
|
fx.Invoke(func(*http.Server) {}),
|
2024-01-28 07:20:59 +00:00
|
|
|
).Run()
|
2024-01-12 00:11:53 +00:00
|
|
|
}
|