Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
fee3c2b8
authored
2014-01-15 17:19:03 +0800
by
astaxie
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
add Strings interface can return []string sep by ;
Example: peers = one;Two;Three
1 parent
b016102d
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
37 additions
and
2 deletions
config/config.go
config/fake.go
config/ini.go
config/ini_test.go
config/json.go
config/xml.go
config/yaml.go
config/config.go
View file @
fee3c2b
...
...
@@ -6,8 +6,9 @@ import (
// ConfigContainer defines how to get and set value from configuration raw data.
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.
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 @
fee3c2b
...
...
@@ -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 @
fee3c2b
...
...
@@ -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 @
fee3c2b
...
...
@@ -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 @
fee3c2b
...
...
@@ -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 @
fee3c2b
...
...
@@ -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 @
fee3c2b
...
...
@@ -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
Styling with
Markdown
is supported
Attach a file
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 post a comment