Commit 9fdad84f authored by xiemengjun's avatar xiemengjun

add config module

parent e9261b21
package helper
import (
"json"
"io/ioutil"
"log"
)
var config map[string]string
func ReadConfig(filename string) {
contents, err := ioutil.ReadFile(filename)
if err != nil {
log.Exitf("Impossible to read %s", filename, err)
}
data, err := json.Decode(string(contents))
if err != nil {
log.Exitf("Can't parse %s as JSON", filename, err)
}
config = map[string]string{ }
for key, value := range data.(map[string]interface{ }) {
config[key] = value.(string)
}
}
func GetConfig(key string) string {
return config[key];
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment