mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 15:20:54 +00:00
This fixes #2294
This commit is contained in:
parent
5bc3e30653
commit
39d40ba8fa
@ -193,10 +193,14 @@ func (c *ConfigContainer) DefaultStrings(key string, defaultval []string) []stri
|
|||||||
|
|
||||||
// GetSection returns map for the given section
|
// GetSection returns map for the given section
|
||||||
func (c *ConfigContainer) GetSection(section string) (map[string]string, error) {
|
func (c *ConfigContainer) GetSection(section string) (map[string]string, error) {
|
||||||
if v, ok := c.data[section]; ok {
|
if v, ok := c.data[section].(map[string]interface{}); ok {
|
||||||
return v.(map[string]string), nil
|
mapstr := make(map[string]string)
|
||||||
|
for k, val := range v {
|
||||||
|
mapstr[k] = config.ToString(val)
|
||||||
}
|
}
|
||||||
return nil, errors.New("not exist setction")
|
return mapstr, nil
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("section '%s' not found", section)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SaveConfigFile save the config into file
|
// SaveConfigFile save the config into file
|
||||||
|
@ -37,6 +37,10 @@ func TestXML(t *testing.T) {
|
|||||||
<copyrequestbody>true</copyrequestbody>
|
<copyrequestbody>true</copyrequestbody>
|
||||||
<path1>${GOPATH}</path1>
|
<path1>${GOPATH}</path1>
|
||||||
<path2>${GOPATH||/home/go}</path2>
|
<path2>${GOPATH||/home/go}</path2>
|
||||||
|
<mysection>
|
||||||
|
<id>1</id>
|
||||||
|
<name>MySection</name>
|
||||||
|
</mysection>
|
||||||
</config>
|
</config>
|
||||||
`
|
`
|
||||||
keyValue = map[string]interface{}{
|
keyValue = map[string]interface{}{
|
||||||
@ -65,11 +69,22 @@ func TestXML(t *testing.T) {
|
|||||||
}
|
}
|
||||||
f.Close()
|
f.Close()
|
||||||
defer os.Remove("testxml.conf")
|
defer os.Remove("testxml.conf")
|
||||||
|
|
||||||
xmlconf, err := config.NewConfig("xml", "testxml.conf")
|
xmlconf, err := config.NewConfig("xml", "testxml.conf")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var xmlsection map[string]string
|
||||||
|
xmlsection, err = xmlconf.GetSection("mysection")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(xmlsection) == 0 {
|
||||||
|
t.Error("section should not be empty")
|
||||||
|
}
|
||||||
|
|
||||||
for k, v := range keyValue {
|
for k, v := range keyValue {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
Loading…
Reference in New Issue
Block a user