1
0
mirror of https://github.com/astaxie/beego.git synced 2025-07-06 06:20:19 +00:00

Config support get environment variable

get environment variable if config item  has prefix "$ENV_" .
e.g.
```ini
[demo]
password = $ENV_MyPWD
```
This commit is contained in:
ysqi
2016-01-27 20:46:30 +08:00
parent 4ce094a29a
commit cd31c816cc
10 changed files with 222 additions and 32 deletions

View File

@ -286,6 +286,11 @@ func (c *IniConfigContainer) DefaultStrings(key string, defaultval []string) []s
// GetSection returns map for the given section
func (c *IniConfigContainer) GetSection(section string) (map[string]string, error) {
if v, ok := c.data[section]; ok {
for k, vv := range v {
if env, ok := Getenv(vv); ok {
v[k] = env
}
}
return v, nil
}
return nil, errors.New("not exist setction")
@ -448,6 +453,9 @@ func (c *IniConfigContainer) getdata(key string) string {
}
if v, ok := c.data[section]; ok {
if vv, ok := v[k]; ok {
if env, ok := Getenv(vv); ok {
return env
}
return vv
}
}