add config module
Showing
1 changed file
with
28 additions
and
0 deletions
helper/config.go
0 → 100644
| 1 | package helper | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "json" | ||
| 5 | "io/ioutil" | ||
| 6 | "log" | ||
| 7 | ) | ||
| 8 | |||
| 9 | var config map[string]string | ||
| 10 | |||
| 11 | func ReadConfig(filename string) { | ||
| 12 | contents, err := ioutil.ReadFile(filename) | ||
| 13 | if err != nil { | ||
| 14 | log.Exitf("Impossible to read %s", filename, err) | ||
| 15 | } | ||
| 16 | data, err := json.Decode(string(contents)) | ||
| 17 | if err != nil { | ||
| 18 | log.Exitf("Can't parse %s as JSON", filename, err) | ||
| 19 | } | ||
| 20 | config = map[string]string{ } | ||
| 21 | for key, value := range data.(map[string]interface{ }) { | ||
| 22 | config[key] = value.(string) | ||
| 23 | } | ||
| 24 | } | ||
| 25 | |||
| 26 | func GetConfig(key string) string { | ||
| 27 | return config[key]; | ||
| 28 | } | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or sign in to post a comment