From 8eaff635db262c7fe169ec86aa4203229b4c8635 Mon Sep 17 00:00:00 2001 From: Anton Korotkov <106995168+korotkov-aerospike@users.noreply.github.com> Date: Mon, 2 Dec 2024 11:01:47 +0200 Subject: [PATCH] Initialize service configuration with default values (#278) use configWithDefaultValues --- .../server/configuration/configuration_manager.go | 2 +- pkg/dto/config.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/server/configuration/configuration_manager.go b/internal/server/configuration/configuration_manager.go index e2f02663..1302b21f 100644 --- a/internal/server/configuration/configuration_manager.go +++ b/internal/server/configuration/configuration_manager.go @@ -52,7 +52,7 @@ func readConfig(reader io.Reader, nsValidator service.NamespaceValidator) (*mode } slog.Info("Service configuration:\n" + string(configBytes)) - config := &dto.Config{} + config := dto.NewConfigWithDefaultValues() if err := yaml.Unmarshal(configBytes, config); err != nil { return nil, fmt.Errorf("failed to unmarshal configuration: %w", err) } diff --git a/pkg/dto/config.go b/pkg/dto/config.go index 7dc54ee7..03f1a760 100644 --- a/pkg/dto/config.go +++ b/pkg/dto/config.go @@ -128,6 +128,17 @@ func (c *Config) validate() error { return nil } +// NewConfigWithDefaultValues returns a new Config with default values. +func NewConfigWithDefaultValues() *Config { + return &Config{ + ServiceConfig: NewBackupServiceConfigWithDefaultValues(), + Storage: map[string]*Storage{}, + BackupRoutines: map[string]*BackupRoutine{}, + BackupPolicies: map[string]*BackupPolicy{}, + AerospikeClusters: map[string]*AerospikeCluster{}, + } +} + func (c *Config) ToModel(nsValidator service.NamespaceValidator) (*model.Config, error) { if err := c.validate(); err != nil { return nil, fmt.Errorf("configuration validation failed: %w", err)