mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 12:50:55 +00:00
add Strings interface can return []string sep by ;
Example: peers = one;Two;Three
This commit is contained in:
parent
b016102d34
commit
fee3c2b8f9
@ -8,6 +8,7 @@ import (
|
|||||||
type ConfigContainer interface {
|
type ConfigContainer interface {
|
||||||
Set(key, val string) error // support section::key type in given key when using ini type.
|
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.
|
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)
|
Int(key string) (int, error)
|
||||||
Int64(key string) (int64, error)
|
Int64(key string) (int64, error)
|
||||||
Bool(key string) (bool, error)
|
Bool(key string) (bool, error)
|
||||||
|
@ -25,6 +25,10 @@ func (c *fakeConfigContainer) String(key string) string {
|
|||||||
return c.getData(key)
|
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) {
|
func (c *fakeConfigContainer) Int(key string) (int, error) {
|
||||||
return strconv.Atoi(c.getData(key))
|
return strconv.Atoi(c.getData(key))
|
||||||
}
|
}
|
||||||
|
@ -146,6 +146,11 @@ func (c *IniConfigContainer) String(key string) string {
|
|||||||
return c.getdata(key)
|
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.
|
// WriteValue writes a new value for key.
|
||||||
// if write to one section, the key need be "section::key".
|
// if write to one section, the key need be "section::key".
|
||||||
// if the section is not existed, it panics.
|
// if the section is not existed, it panics.
|
||||||
|
@ -19,6 +19,7 @@ copyrequestbody = true
|
|||||||
key1="asta"
|
key1="asta"
|
||||||
key2 = "xie"
|
key2 = "xie"
|
||||||
CaseInsensitive = true
|
CaseInsensitive = true
|
||||||
|
peers = one;two;three
|
||||||
`
|
`
|
||||||
|
|
||||||
func TestIni(t *testing.T) {
|
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 {
|
if v, err := iniconf.Bool("demo::caseinsensitive"); err != nil || v != true {
|
||||||
t.Fatal("get demo.caseinsensitive error")
|
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")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -116,6 +116,11 @@ func (c *JsonConfigContainer) String(key string) string {
|
|||||||
return ""
|
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.
|
// WriteValue writes a new value for key.
|
||||||
func (c *JsonConfigContainer) Set(key, val string) error {
|
func (c *JsonConfigContainer) Set(key, val string) error {
|
||||||
c.Lock()
|
c.Lock()
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/beego/x2j"
|
"github.com/beego/x2j"
|
||||||
@ -72,6 +73,11 @@ func (c *XMLConfigContainer) String(key string) string {
|
|||||||
return ""
|
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.
|
// WriteValue writes a new value for key.
|
||||||
func (c *XMLConfigContainer) Set(key, val string) error {
|
func (c *XMLConfigContainer) Set(key, val string) error {
|
||||||
c.Lock()
|
c.Lock()
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/beego/goyaml2"
|
"github.com/beego/goyaml2"
|
||||||
@ -117,6 +118,11 @@ func (c *YAMLConfigContainer) String(key string) string {
|
|||||||
return ""
|
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.
|
// WriteValue writes a new value for key.
|
||||||
func (c *YAMLConfigContainer) Set(key, val string) error {
|
func (c *YAMLConfigContainer) Set(key, val string) error {
|
||||||
c.Lock()
|
c.Lock()
|
||||||
|
Loading…
Reference in New Issue
Block a user