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:
@ -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
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user