Skip to content

Commit

Permalink
refine function signature in config module
Browse files Browse the repository at this point in the history
  • Loading branch information
louyuting committed Oct 15, 2020
1 parent effba07 commit 6e6fcc0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion api/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func initSentinel(configPath string) (err error) {
}
}()
// Initialize general config and logging module.
if err = config.ApplyConfigFile(configPath); err != nil {
if err = config.ApplyYamlConfigFile(configPath); err != nil {
return err
}
if err = config.OverrideConfigFromEnvAndInitLog(); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions core/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ func ResetGlobalConfig(config *Entity) {
globalCfg = config
}

// ApplyConfigFile loads general configuration from the given file.
func ApplyConfigFile(configPath string) error {
// ApplyYamlConfigFile loads general configuration from the given YAML file.
func ApplyYamlConfigFile(configPath string) error {
// Priority: system environment > YAML file > default config
if util.IsBlank(configPath) {
// If the config file path is absent, Sentinel will try to resolve it from the system env.
Expand All @@ -34,7 +34,7 @@ func ApplyConfigFile(configPath string) error {
}
// First Sentinel will try to load config from the given file.
// If the path is empty (not set), Sentinel will use the default config.
return loadFromYamlFile(configPath)
return loadGlobalConfigFromYamlFile(configPath)
}

func OverrideConfigFromEnvAndInitLog() error {
Expand Down Expand Up @@ -66,7 +66,7 @@ func OverrideConfigFromEnvAndInitLog() error {
return nil
}

func loadFromYamlFile(filePath string) error {
func loadGlobalConfigFromYamlFile(filePath string) error {
if filePath == DefaultConfigFilename {
if _, err := os.Stat(DefaultConfigFilename); err != nil {
//use default globalCfg.
Expand Down
6 changes: 3 additions & 3 deletions core/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func TestLoadFromYamlFile(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := loadFromYamlFile(tt.args.filePath); (err != nil) != tt.wantErr {
t.Errorf("loadFromYamlFile() error = %v, wantErr %v", err, tt.wantErr)
if err := loadGlobalConfigFromYamlFile(tt.args.filePath); (err != nil) != tt.wantErr {
t.Errorf("loadGlobalConfigFromYamlFile() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
Expand All @@ -50,7 +50,7 @@ func TestOverrideFromSystemEnv(t *testing.T) {
wantErr: false,
},
}
err := loadFromYamlFile(testDataBaseDir + "sentinel.yml")
err := loadGlobalConfigFromYamlFile(testDataBaseDir + "sentinel.yml")
if err != nil {
t.Errorf("Fail to initialize data.")
}
Expand Down

0 comments on commit 6e6fcc0

Please sign in to comment.