1
0
mirror of https://github.com/astaxie/beego.git synced 2024-12-22 17:40:48 +00:00

add config module

This commit is contained in:
xiemengjun 2012-03-05 22:57:53 +08:00
parent e9261b21e5
commit 9fdad84fd0

28
helper/config.go Normal file
View File

@ -0,0 +1,28 @@
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];
}