Created
July 28, 2020 13:33
-
-
Save jfeng45/67e0bf7aa1ac0462b4a21d0ce3e8d7bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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