diff --git a/config/config.go b/config/config.go index 8cdb11d..e508714 100644 --- a/config/config.go +++ b/config/config.go @@ -277,10 +277,17 @@ type SectionGRPC struct { Port string `yaml:"port"` } +func setDefault() { + viper.SetDefault("ios.max_concurrent_pushes", uint(100)) +} + // LoadConf load config from file and read in environment variables that match func LoadConf(confPath ...string) (*ConfYaml, error) { conf := &ConfYaml{} + // load default values + setDefault() + viper.SetConfigType("yaml") viper.AutomaticEnv() // read in environment variables that match viper.SetEnvPrefix("gorush") // will be uppercased automatically diff --git a/config/config_test.go b/config/config_test.go index ec3df03..9b957c5 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -17,6 +17,15 @@ func TestMissingFile(t *testing.T) { assert.NotNil(t, err) } +func TestEmptyConfig(t *testing.T) { + conf, err := LoadConf("testdata/empty.yml") + if err != nil { + panic("failed to load config.yml from file") + } + + assert.Equal(t, uint(100), conf.Ios.MaxConcurrentPushes) +} + type ConfigTestSuite struct { suite.Suite ConfGorushDefault *ConfYaml diff --git a/config/testdata/empty.yml b/config/testdata/empty.yml new file mode 100644 index 0000000..e69de29