46 lines
1.6 KiB
Go
46 lines
1.6 KiB
Go
package biz
|
|
|
|
import "context"
|
|
|
|
type DatabaseConfig struct {
|
|
Driver, Host, Port, User, Password, Name, Path, Config, Template, AdminPassword string
|
|
APIs []*API
|
|
}
|
|
|
|
type InitializationRepo interface {
|
|
IsInitialized(context.Context) (bool, error)
|
|
Initialize(context.Context, *DatabaseConfig) error
|
|
PersistConfig(context.Context) error
|
|
PersistAdminConfig(context.Context, []byte) error
|
|
PersistRuntimeConfig(context.Context, []byte, []byte) error
|
|
ReloadConfig(context.Context) error
|
|
}
|
|
|
|
type SystemConfigUsecase struct{ repo InitializationRepo }
|
|
|
|
func NewSystemConfigUsecase(repo InitializationRepo) *SystemConfigUsecase {
|
|
return &SystemConfigUsecase{repo: repo}
|
|
}
|
|
|
|
func (uc *SystemConfigUsecase) IsInitialized(ctx context.Context) (bool, error) {
|
|
return uc.repo.IsInitialized(ctx)
|
|
}
|
|
func (uc *SystemConfigUsecase) Initialize(ctx context.Context, config *DatabaseConfig) error {
|
|
if config == nil || len(config.AdminPassword) < 6 {
|
|
return ErrInvalidCredentials
|
|
}
|
|
return uc.repo.Initialize(ctx, config)
|
|
}
|
|
func (uc *SystemConfigUsecase) PersistConfig(ctx context.Context) error {
|
|
return uc.repo.PersistConfig(ctx)
|
|
}
|
|
func (uc *SystemConfigUsecase) PersistAdminConfig(ctx context.Context, value []byte) error {
|
|
return uc.repo.PersistAdminConfig(ctx, value)
|
|
}
|
|
func (uc *SystemConfigUsecase) PersistRuntimeConfig(ctx context.Context, data, admin []byte) error {
|
|
return uc.repo.PersistRuntimeConfig(ctx, data, admin)
|
|
}
|
|
func (uc *SystemConfigUsecase) ReloadConfig(ctx context.Context) error {
|
|
return uc.repo.ReloadConfig(ctx)
|
|
}
|