Skip to content

Commit 1834968

Browse files
authored
Merge pull request #6 from kilisima/fix-argument
fix Get() function. argument type string to interface{}
2 parents 0784bcd + 1495e07 commit 1834968

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

simpleyaml.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func NewYaml(body []byte) (*Yaml, error) {
5252
//
5353
// Example:
5454
// y.Get("xx").Get("yy").Int()
55-
func (y *Yaml) Get(key string) *Yaml {
55+
func (y *Yaml) Get(key interface{}) *Yaml {
5656
m, err := y.Map()
5757
if err == nil {
5858
if val, ok := m[key]; ok {
@@ -66,7 +66,7 @@ func (y *Yaml) Get(key string) *Yaml {
6666
//
6767
// Example:
6868
// y.GetPath("bb", "cc").Int()
69-
func (y *Yaml) GetPath(branch ...string) *Yaml {
69+
func (y *Yaml) GetPath(branch ...interface{}) *Yaml {
7070
yin := y
7171
for _, p := range branch {
7272
yin = yin.Get(p)

simpleyaml_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ name: smallfish
99
age: 99
1010
float: 3.14159
1111
bool: true
12+
0: IntKey
1213
emails:
1314
- xxx@xx.com
1415
- yyy@yy.com
@@ -51,6 +52,22 @@ func TestString(t *testing.T) {
5152
}
5253
}
5354

55+
func TestStringFromIntKey(t *testing.T) {
56+
y, err := NewYaml(data)
57+
if err != nil {
58+
t.Fatal("init yaml failed")
59+
}
60+
v, err := y.Get(0).String()
61+
if err != nil {
62+
t.Fatal("get yaml failed")
63+
}
64+
65+
t.Log(v)
66+
if v != "IntKey" {
67+
t.Fatal("match IntKey failed")
68+
}
69+
}
70+
5471
func TestFloat(t *testing.T) {
5572
y, err := NewYaml(data)
5673
if err != nil {
@@ -156,3 +173,4 @@ func TestMap(t *testing.T) {
156173
t.Fatal("fail to check number of keys")
157174
}
158175
}
176+

0 commit comments

Comments
 (0)