Skip to content

Commit

Permalink
Merge pull request #508 from jumpserver/dev
Browse files Browse the repository at this point in the history
perf: 配置加载顺序调整 (#507)
  • Loading branch information
LeeEirc committed Dec 11, 2020
2 parents 637a41d + 027f4e1 commit ee146e1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
11 changes: 7 additions & 4 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,14 @@ func (c *Config) LoadFromEnv() error {
}

func (c *Config) Load(filepath string) error {
if err := c.LoadFromYAMLPath(filepath); err == nil {
return err
var err error
log.Print("Config Load from env first")
_ = c.LoadFromEnv()
if _, err = os.Stat(filepath); err == nil {
log.Printf("Config reload from file: %s", filepath)
return c.LoadFromYAMLPath(filepath)
}
log.Print("Load from env")
return c.LoadFromEnv()
return nil
}

var lock = new(sync.RWMutex)
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"testing"
)

func TestConfig_LoadFromYAMLPath(t *testing.T) {
err := Conf.LoadFromYAMLPath("./test_config.yml")
func TestConfig_Load(t *testing.T) {
err := Conf.Load("./test_config.yml")
if err != nil {
t.Errorf("Load from yaml faild: %v", err)
}
Expand Down
1 change: 0 additions & 1 deletion pkg/config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ func Initial(confPath string) {
if err := Conf.Load(confPath); err != nil {
log.Fatal(err)
}
log.Printf("Config file Path: %s\n", confPath)
Conf.EnsureConfigValid()
}

Expand Down

0 comments on commit ee146e1

Please sign in to comment.