Skip to content
Snippets Groups Projects
Commit 996ccf81 authored by Valerii Kalashnikov's avatar Valerii Kalashnikov
Browse files

Merge branch 'modeToConfig' into 'main'

mode in baseConfig

See merge request !16
parents 3bb09e39 fbc3fcac
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ package config ...@@ -3,6 +3,7 @@ package config
import ( import (
"errors" "errors"
"fmt" "fmt"
"gitlab.eclipse.org/eclipse/xfsc/libraries/microservice/core/pkg/server"
"strings" "strings"
"github.com/spf13/viper" "github.com/spf13/viper"
...@@ -13,10 +14,11 @@ var viperInstance = viper.New() ...@@ -13,10 +14,11 @@ var viperInstance = viper.New()
// BaseConfig can be used to import the base config parameters in the applications config struct. // BaseConfig can be used to import the base config parameters in the applications config struct.
// Please use with tag `mapstructure:",squash"`. // Please use with tag `mapstructure:",squash"`.
type BaseConfig struct { type BaseConfig struct {
LogLevel string `mapstructure:"logLevel" envconfig:"LOG_LEVEL" default:"info"` LogLevel string `mapstructure:"logLevel" envconfig:"LOG_LEVEL" default:"info"`
IsDev bool `mapstructure:"isDev" envconfig:"IS_DEV" default:"false"` IsDev bool `mapstructure:"isDev" envconfig:"IS_DEV" default:"false"`
ListenAddr string `mapstructure:"listenAddr" envconfig:"LISTEN_ADDR" default:"127.0.0.1"` ListenAddr string `mapstructure:"listenAddr" envconfig:"LISTEN_ADDR" default:"127.0.0.1"`
ListenPort int `mapstructure:"listenPort" envconfig:"LISTEN_PORT" default:"8080"` ListenPort int `mapstructure:"listenPort" envconfig:"LISTEN_PORT" default:"8080"`
ServerMode server.ServerMode `mapstructure:"serverMode" default:"production"`
} }
// LoadConfig sets given defaults and read in given config. // LoadConfig sets given defaults and read in given config.
...@@ -57,6 +59,7 @@ func setDefaults(defaults map[string]any) { ...@@ -57,6 +59,7 @@ func setDefaults(defaults map[string]any) {
viperInstance.SetDefault("logLevel", "info") viperInstance.SetDefault("logLevel", "info")
viperInstance.SetDefault("listenAddr", "127.0.0.1") viperInstance.SetDefault("listenAddr", "127.0.0.1")
viperInstance.SetDefault("listenPort", 8080) viperInstance.SetDefault("listenPort", 8080)
viperInstance.SetDefault("serverMode", server.ModeProduction)
for key, value := range defaults { for key, value := range defaults {
viperInstance.SetDefault(key, value) viperInstance.SetDefault(key, value)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment