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
fee3c2b8
Commit
fee3c2b8
authored
Jan 15, 2014
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add Strings interface can return []string sep by ;
Example: peers = one;Two;Three
parent
b016102d
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
35 additions
and
0 deletions
+35
-0
config.go
config/config.go
+1
-0
fake.go
config/fake.go
+4
-0
ini.go
config/ini.go
+5
-0
ini_test.go
config/ini_test.go
+8
-0
json.go
config/json.go
+5
-0
xml.go
config/xml.go
+6
-0
yaml.go
config/yaml.go
+6
-0
No files found.
config/config.go
View file @
fee3c2b8
...
...
@@ -8,6 +8,7 @@ import (
type
ConfigContainer
interface
{
Set
(
key
,
val
string
)
error
// support section::key type in given key when using ini type.
String
(
key
string
)
string
// support section::key type in key string when using ini and json type; Int,Int64,Bool,Float,DIY are same.
Strings
(
key
string
)
[]
string
//get string slice
Int
(
key
string
)
(
int
,
error
)
Int64
(
key
string
)
(
int64
,
error
)
Bool
(
key
string
)
(
bool
,
error
)
...
...
config/fake.go
View file @
fee3c2b8
...
...
@@ -25,6 +25,10 @@ func (c *fakeConfigContainer) String(key string) string {
return
c
.
getData
(
key
)
}
func
(
c
*
fakeConfigContainer
)
Strings
(
key
string
)
[]
string
{
return
strings
.
Split
(
c
.
getData
(
key
),
";"
)
}
func
(
c
*
fakeConfigContainer
)
Int
(
key
string
)
(
int
,
error
)
{
return
strconv
.
Atoi
(
c
.
getData
(
key
))
}
...
...
config/ini.go
View file @
fee3c2b8
...
...
@@ -146,6 +146,11 @@ func (c *IniConfigContainer) String(key string) string {
return
c
.
getdata
(
key
)
}
// Strings returns the []string value for a given key.
func
(
c
*
IniConfigContainer
)
Strings
(
key
string
)
[]
string
{
return
strings
.
Split
(
c
.
String
(
key
),
";"
)
}
// WriteValue writes a new value for key.
// if write to one section, the key need be "section::key".
// if the section is not existed, it panics.
...
...
config/ini_test.go
View file @
fee3c2b8
...
...
@@ -19,6 +19,7 @@ copyrequestbody = true
key1="asta"
key2 = "xie"
CaseInsensitive = true
peers = one;two;three
`
func
TestIni
(
t
*
testing
.
T
)
{
...
...
@@ -78,4 +79,11 @@ func TestIni(t *testing.T) {
if
v
,
err
:=
iniconf
.
Bool
(
"demo::caseinsensitive"
);
err
!=
nil
||
v
!=
true
{
t
.
Fatal
(
"get demo.caseinsensitive error"
)
}
if
data
:=
iniconf
.
Strings
(
"demo::peers"
);
len
(
data
)
!=
3
{
t
.
Fatal
(
"get strings error"
,
data
)
}
else
if
data
[
0
]
!=
"one"
{
t
.
Fatal
(
"get first params error not equat to one"
)
}
}
config/json.go
View file @
fee3c2b8
...
...
@@ -116,6 +116,11 @@ func (c *JsonConfigContainer) String(key string) string {
return
""
}
// Strings returns the []string value for a given key.
func
(
c
*
JsonConfigContainer
)
Strings
(
key
string
)
[]
string
{
return
strings
.
Split
(
c
.
String
(
key
),
";"
)
}
// WriteValue writes a new value for key.
func
(
c
*
JsonConfigContainer
)
Set
(
key
,
val
string
)
error
{
c
.
Lock
()
...
...
config/xml.go
View file @
fee3c2b8
...
...
@@ -5,6 +5,7 @@ import (
"io/ioutil"
"os"
"strconv"
"strings"
"sync"
"github.com/beego/x2j"
...
...
@@ -72,6 +73,11 @@ func (c *XMLConfigContainer) String(key string) string {
return
""
}
// Strings returns the []string value for a given key.
func
(
c
*
XMLConfigContainer
)
Strings
(
key
string
)
[]
string
{
return
strings
.
Split
(
c
.
String
(
key
),
";"
)
}
// WriteValue writes a new value for key.
func
(
c
*
XMLConfigContainer
)
Set
(
key
,
val
string
)
error
{
c
.
Lock
()
...
...
config/yaml.go
View file @
fee3c2b8
...
...
@@ -7,6 +7,7 @@ import (
"io/ioutil"
"log"
"os"
"strings"
"sync"
"github.com/beego/goyaml2"
...
...
@@ -117,6 +118,11 @@ func (c *YAMLConfigContainer) String(key string) string {
return
""
}
// Strings returns the []string value for a given key.
func
(
c
*
YAMLConfigContainer
)
Strings
(
key
string
)
[]
string
{
return
strings
.
Split
(
c
.
String
(
key
),
";"
)
}
// WriteValue writes a new value for key.
func
(
c
*
YAMLConfigContainer
)
Set
(
key
,
val
string
)
error
{
c
.
Lock
()
...
...
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