Skip to content

Commit

Permalink
Allow setting multiple configs via commandline
Browse files Browse the repository at this point in the history
  • Loading branch information
arriven committed Mar 4, 2022
1 parent 5e567c2 commit 4928009
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,14 +578,26 @@ func panicHandler() {
var defaultConfig = `
`

func updateConfig(configPath, backupConfig string) (config *Config, err error) {
configPaths := strings.Split(configPath, ",")
for _, path := range configPaths {
config, err = fetchConfig(path)
if err == nil {
return config, nil
}
}
err = json.Unmarshal([]byte(backupConfig), &config)
return config, err
}

func main() {
var configPath string
var backupConfig string
var refreshTimeout time.Duration
var logLevel logs.Level
var help bool
var metricsPath string
flag.StringVar(&configPath, "c", "https://raw.githubusercontent.com/db1000n-coordinators/LoadTestConfig/main/config.json", "path to a config file, can be web endpoint")
flag.StringVar(&configPath, "c", "https://raw.githubusercontent.com/db1000n-coordinators/LoadTestConfig/main/config.json", "path to config files, separated by a comma, each path can be a web endpoint")
flag.StringVar(&backupConfig, "b", defaultConfig, "path to a backup config file in case primary one is unavailable")
flag.DurationVar(&refreshTimeout, "r", time.Minute, "refresh timeout for updating the config")
flag.IntVar(&logLevel, "l", logs.Info, "logging level. 0 - Debug, 1 - Info, 2 - Warning, 3 - Error")
Expand All @@ -609,14 +621,10 @@ func main() {
cancel()
}()
for {
config, err := fetchConfig(configPath)
config, err := updateConfig(configPath, backupConfig)
if err != nil {
l.Debug("error fetching main config, retrieving backup ones")
err = json.Unmarshal([]byte(backupConfig), &config)
if err != nil {
l.Warning("fetching json config: %v\n", err)
continue
}
l.Warning("fetching json config: %v\n", err)
continue
}
if cancel != nil {
cancel()
Expand Down

0 comments on commit 4928009

Please sign in to comment.