Skip to content

Instantly share code, notes, and snippets.

@jfeng45
Created July 28, 2020 13:33
Show Gist options
  • Save jfeng45/67e0bf7aa1ac0462b4a21d0ce3e8d7bf to your computer and use it in GitHub Desktop.
Save jfeng45/67e0bf7aa1ac0462b4a21d0ce3e8d7bf to your computer and use it in GitHub Desktop.
func BuildConfig(filename ...string) (*AppConfig, error) {
if len(filename) == 1 {
return buildConfigFromFile(filename[0])
} else {
return BuildConfigWithoutFile()
}
}
func buildConfigFromFile(filename string) (*AppConfig, error) {
var ac AppConfig
file, err := ioutil.ReadFile(filename)
if err != nil {
return nil, errors.Wrap(err, "read error")
}
err = yaml.Unmarshal(file, &ac)
if err != nil {
return nil, errors.Wrap(err, "unmarshal")
}
fmt.Println("appConfig:", ac)
return &ac, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment