mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 07:10:55 +00:00
add config module
This commit is contained in:
parent
e9261b21e5
commit
9fdad84fd0
28
helper/config.go
Normal file
28
helper/config.go
Normal 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];
|
||||
}
|
Loading…
Reference in New Issue
Block a user