优化结构
This commit is contained in:
@@ -12,36 +12,36 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Backend is the infrastructure boundary required by application
|
||||
// initialization and runtime configuration management.
|
||||
type Backend interface {
|
||||
IsInitialized(context.Context) (bool, error)
|
||||
InitializeDatabase(context.Context, *system.DatabaseConfig, func(context.Context, *gorm.DB) error) error
|
||||
PersistConfig(context.Context) error
|
||||
PersistRuntimeConfig(context.Context, *config.Config) error
|
||||
ReloadConfig(context.Context) error
|
||||
Config() *config.Config
|
||||
}
|
||||
|
||||
// Repo adapts Backend to system.InitializationRepo. Backend is embedded so the
|
||||
// four identically shaped methods are promoted instead of hand-forwarded; this
|
||||
// file adds only what the two boundaries genuinely disagree on.
|
||||
type Repo struct {
|
||||
backend Backend
|
||||
Backend
|
||||
catalog platformmodule.Catalog
|
||||
}
|
||||
|
||||
func NewRepo(backend Backend, catalog platformmodule.Catalog) system.InitializationRepo {
|
||||
return &Repo{backend: backend, catalog: catalog}
|
||||
}
|
||||
|
||||
func (r *Repo) IsInitialized(ctx context.Context) (bool, error) {
|
||||
return r.backend.IsInitialized(ctx)
|
||||
return &Repo{Backend: backend, catalog: catalog}
|
||||
}
|
||||
|
||||
// Initialize layers system and task seeding on top of the backend's database
|
||||
// lifecycle, which is the one place the two interfaces differ in shape.
|
||||
func (r *Repo) Initialize(ctx context.Context, input *system.DatabaseConfig) error {
|
||||
return r.backend.InitializeDatabase(ctx, input, func(ctx context.Context, db *gorm.DB) error {
|
||||
return r.InitializeDatabase(ctx, input, func(ctx context.Context, db *gorm.DB) error {
|
||||
if err := datasystem.SeedSystemWithCatalog(ctx, db, input, r.catalog); err != nil {
|
||||
return err
|
||||
}
|
||||
return datatask.SeedDefaults(ctx, db, r.catalog.DefaultTimedTasks())
|
||||
})
|
||||
}
|
||||
|
||||
func (r *Repo) PersistConfig(ctx context.Context) error {
|
||||
return r.backend.PersistConfig(ctx)
|
||||
}
|
||||
|
||||
func (r *Repo) PersistRuntimeConfig(ctx context.Context, value *config.Config) error {
|
||||
return r.backend.PersistRuntimeConfig(ctx, value)
|
||||
}
|
||||
|
||||
func (r *Repo) ReloadConfig(ctx context.Context) error {
|
||||
return r.backend.ReloadConfig(ctx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user