mirror of
https://github.com/astaxie/beego.git
synced 2024-11-26 00:01:29 +00:00
code style simplify
This commit is contained in:
parent
84da1c924a
commit
a6ced64441
@ -7,7 +7,7 @@
|
|||||||
// @license http://github.com/astaxie/beego/blob/master/LICENSE
|
// @license http://github.com/astaxie/beego/blob/master/LICENSE
|
||||||
//
|
//
|
||||||
// @authors astaxie
|
// @authors astaxie
|
||||||
package config
|
package xml
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
@ -24,27 +24,27 @@ import (
|
|||||||
// XmlConfig is a xml config parser and implements Config interface.
|
// XmlConfig is a xml config parser and implements Config interface.
|
||||||
// xml configurations should be included in <config></config> tag.
|
// xml configurations should be included in <config></config> tag.
|
||||||
// only support key/value pair as <key>value</key> as each item.
|
// only support key/value pair as <key>value</key> as each item.
|
||||||
type XMLConfig struct {
|
type XMLConfig struct{}
|
||||||
}
|
|
||||||
|
|
||||||
// Parse returns a ConfigContainer with parsed xml config map.
|
// Parse returns a ConfigContainer with parsed xml config map.
|
||||||
func (xmls *XMLConfig) Parse(filename string) (config.ConfigContainer, error) {
|
func (xc *XMLConfig) Parse(filename string) (config.ConfigContainer, error) {
|
||||||
file, err := os.Open(filename)
|
file, err := os.Open(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
x := &XMLConfigContainer{
|
|
||||||
data: make(map[string]interface{}),
|
x := &XMLConfigContainer{data: make(map[string]interface{})}
|
||||||
}
|
|
||||||
content, err := ioutil.ReadAll(file)
|
content, err := ioutil.ReadAll(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
d, err := x2j.DocToMap(string(content))
|
d, err := x2j.DocToMap(string(content))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
x.data = d["config"].(map[string]interface{})
|
x.data = d["config"].(map[string]interface{})
|
||||||
return x, nil
|
return x, nil
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
// @license http://github.com/astaxie/beego/blob/master/LICENSE
|
// @license http://github.com/astaxie/beego/blob/master/LICENSE
|
||||||
//
|
//
|
||||||
// @authors astaxie
|
// @authors astaxie
|
||||||
package config
|
package xml
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
Loading…
Reference in New Issue
Block a user