Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
ae8bb8ce
Commit
ae8bb8ce
authored
Jul 17, 2014
by
astaxie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #701 from fuxiaohei/develop
code style simplify
parents
69094b27
38188098
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
33 deletions
+30
-33
json.go
config/json.go
+3
-3
xml.go
config/xml/xml.go
+7
-7
xml_test.go
config/xml/xml_test.go
+1
-1
yaml.go
config/yaml/yaml.go
+18
-21
yaml_test.go
config/yaml/yaml_test.go
+1
-1
No files found.
config/json.go
View file @
ae8bb8ce
...
@@ -151,12 +151,12 @@ func (c *JsonConfigContainer) getData(key string) interface{} {
...
@@ -151,12 +151,12 @@ func (c *JsonConfigContainer) getData(key string) interface{} {
}
}
for
_
,
key
:=
range
sectionKey
[
1
:
]
{
for
_
,
key
:=
range
sectionKey
[
1
:
]
{
if
v
,
ok
:=
curValue
.
(
map
[
string
]
interface
{});
ok
{
if
v
,
ok
:=
curValue
.
(
map
[
string
]
interface
{});
ok
{
if
v2
,
ok
:=
v
[
key
];
ok
{
if
curValue
,
ok
=
v
[
key
];
!
ok
{
return
v2
return
nil
}
}
}
}
}
}
return
nil
return
curValue
}
}
if
v
,
ok
:=
c
.
data
[
key
];
ok
{
if
v
,
ok
:=
c
.
data
[
key
];
ok
{
return
v
return
v
...
...
config/xml/xml.go
View file @
ae8bb8ce
...
@@ -7,7 +7,7 @@
...
@@ -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 (
...
@@ -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
(
x
mls
*
XMLConfig
)
Parse
(
filename
string
)
(
config
.
ConfigContainer
,
error
)
{
func
(
x
c
*
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
}
}
...
...
config/xml/xml_test.go
View file @
ae8bb8ce
...
@@ -7,7 +7,7 @@
...
@@ -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"
...
...
config/yaml/yaml.go
View file @
ae8bb8ce
...
@@ -7,7 +7,7 @@
...
@@ -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
yaml
import
(
import
(
"bytes"
"bytes"
...
@@ -24,39 +24,36 @@ import (
...
@@ -24,39 +24,36 @@ import (
)
)
// YAMLConfig is a yaml config parser and implements Config interface.
// YAMLConfig is a yaml config parser and implements Config interface.
type
YAMLConfig
struct
{
type
YAMLConfig
struct
{}
}
// Parse returns a ConfigContainer with parsed yaml config map.
// Parse returns a ConfigContainer with parsed yaml config map.
func
(
yaml
*
YAMLConfig
)
Parse
(
filename
string
)
(
config
.
ConfigContainer
,
error
)
{
func
(
yaml
*
YAMLConfig
)
Parse
(
filename
string
)
(
y
config
.
ConfigContainer
,
err
error
)
{
y
:=
&
YAMLConfigContainer
{
data
:
make
(
map
[
string
]
interface
{}),
}
cnf
,
err
:=
ReadYmlReader
(
filename
)
cnf
,
err
:=
ReadYmlReader
(
filename
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
}
}
y
.
data
=
cnf
y
=
&
YAMLConfigContainer
{
return
y
,
nil
data
:
cnf
,
}
return
}
}
// Read yaml file to map.
// Read yaml file to map.
// if json like, use json package, unless goyaml2 package.
// if json like, use json package, unless goyaml2 package.
func
ReadYmlReader
(
path
string
)
(
cnf
map
[
string
]
interface
{},
err
error
)
{
func
ReadYmlReader
(
path
string
)
(
cnf
map
[
string
]
interface
{},
err
error
)
{
err
=
nil
f
,
err
:=
os
.
Open
(
path
)
f
,
err
:=
os
.
Open
(
path
)
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
defer
f
.
Close
()
defer
f
.
Close
()
err
=
nil
buf
,
err
:=
ioutil
.
ReadAll
(
f
)
buf
,
err
:=
ioutil
.
ReadAll
(
f
)
if
err
!=
nil
||
len
(
buf
)
<
3
{
if
err
!=
nil
||
len
(
buf
)
<
3
{
return
return
}
}
if
string
(
buf
[
0
:
1
])
==
"{"
{
if
string
(
buf
[
0
:
1
])
==
"{"
{
log
.
Println
(
"Look li
le a Json, try it
"
)
log
.
Println
(
"Look li
ke a Json, try json umarshal
"
)
err
=
json
.
Unmarshal
(
buf
,
&
cnf
)
err
=
json
.
Unmarshal
(
buf
,
&
cnf
)
if
err
==
nil
{
if
err
==
nil
{
log
.
Println
(
"It is Json Map"
)
log
.
Println
(
"It is Json Map"
)
...
@@ -64,19 +61,19 @@ func ReadYmlReader(path string) (cnf map[string]interface{}, err error) {
...
@@ -64,19 +61,19 @@ func ReadYmlReader(path string) (cnf map[string]interface{}, err error) {
}
}
}
}
_map
,
_err
:=
goyaml2
.
Read
(
bytes
.
NewBuffer
(
buf
))
data
,
err
:=
goyaml2
.
Read
(
bytes
.
NewBuffer
(
buf
))
if
_err
!=
nil
{
if
err
!=
nil
{
log
.
Println
(
"Goyaml2 ERR>"
,
string
(
buf
),
_err
)
log
.
Println
(
"Goyaml2 ERR>"
,
string
(
buf
),
err
)
//err = goyaml.Unmarshal(buf, &cnf)
err
=
_err
return
return
}
}
if
_map
==
nil
{
if
data
==
nil
{
log
.
Println
(
"Goyaml2 output nil? Pls report bug
\n
"
+
string
(
buf
))
log
.
Println
(
"Goyaml2 output nil? Pls report bug
\n
"
+
string
(
buf
))
return
}
}
cnf
,
ok
:=
_map
.
(
map
[
string
]
interface
{})
cnf
,
ok
:=
data
.
(
map
[
string
]
interface
{})
if
!
ok
{
if
!
ok
{
log
.
Println
(
"Not a Map? >> "
,
string
(
buf
),
_map
)
log
.
Println
(
"Not a Map? >> "
,
string
(
buf
),
data
)
cnf
=
nil
cnf
=
nil
}
}
return
return
...
...
config/yaml/yaml_test.go
View file @
ae8bb8ce
...
@@ -7,7 +7,7 @@
...
@@ -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
yaml
import
(
import
(
"os"
"os"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment