9fdad84f by xiemengjun

add config module

1 parent e9261b21
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
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!