1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-19 06:30:54 +00:00
Beego/beego/helper/config.go
2012-03-07 20:30:33 +08:00

28 lines
538 B
Go

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];
}