fix startup bootstrap recovery and local verification
This commit is contained in:
@@ -18,14 +18,16 @@ import (
|
||||
"github.com/Wei-Shaw/sub2api/internal/server"
|
||||
"github.com/Wei-Shaw/sub2api/internal/server/middleware"
|
||||
"github.com/Wei-Shaw/sub2api/internal/service"
|
||||
"github.com/Wei-Shaw/sub2api/internal/setup"
|
||||
|
||||
"github.com/google/wire"
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
type Application struct {
|
||||
Server *http.Server
|
||||
Cleanup func()
|
||||
Server *http.Server
|
||||
Cleanup func()
|
||||
Bootstrap func() error
|
||||
}
|
||||
|
||||
func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
|
||||
@@ -53,9 +55,10 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
|
||||
|
||||
// Cleanup function provider
|
||||
provideCleanup,
|
||||
provideBootstrap,
|
||||
|
||||
// Application struct
|
||||
wire.Struct(new(Application), "Server", "Cleanup"),
|
||||
wire.Struct(new(Application), "Server", "Cleanup", "Bootstrap"),
|
||||
)
|
||||
return nil, nil
|
||||
}
|
||||
@@ -71,6 +74,28 @@ func provideServiceBuildInfo(buildInfo handler.BuildInfo) service.BuildInfo {
|
||||
}
|
||||
}
|
||||
|
||||
func provideBootstrap(settingService *service.SettingService, userRepo service.UserRepository, cfg *config.Config) func() error {
|
||||
return newBootstrapFunc(settingService.InitializeDefaultSettings, setup.RecoverAutoSetupAdmin, userRepo, cfg)
|
||||
}
|
||||
|
||||
func newBootstrapFunc(
|
||||
initDefaults func(context.Context) error,
|
||||
recoverAdmin func(context.Context, service.UserRepository, *config.Config) error,
|
||||
userRepo service.UserRepository,
|
||||
cfg *config.Config,
|
||||
) func() error {
|
||||
return func() error {
|
||||
ctx := context.Background()
|
||||
if err := initDefaults(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := recoverAdmin(ctx, userRepo, cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func provideCleanup(
|
||||
entClient *ent.Client,
|
||||
rdb *redis.Client,
|
||||
|
||||
Reference in New Issue
Block a user