1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-29 11:21:29 +00:00
Beego/beego/helper/config.go

28 lines
538 B
Go
Raw Normal View History

2012-03-05 14:57:53 +00:00
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];
}