File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ name: smallfish
99age: 99
1010float: 3.14159
1111bool: true
12+ 0: IntKey
1213emails:
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+
5471func 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+
You can’t perform that action at this time.
0 commit comments