1 개요[ | ]
- Go flex
Go
Copy
package main
import (
"fmt"
"github.com/jmnote/flex"
)
func main() {
m := map[string]interface{}{
"ids": []interface{}{1, 2, 3},
"fruits": []interface{}{"apple", "banana"},
}
f := flex.NewFromObject(m)
fmt.Println(f.Get(".ids")) // [1 2 3]
fmt.Println(f.Get(".ids[1]")) // 2
fmt.Println(f.GetInt(".ids[1]")) // 2
fmt.Println(f.GetIntSlice(".ids")[1]) // 2
ids := f.GetIntSlice(".ids")
ids = append(ids, 9)
fmt.Println(ids) // [1 2 3 9]
fruits := f.GetStringSlice(".fruits")
fruits = append(fruits, "pear")
fmt.Println(fruits) // [apple banana pear]
m["ids"] = append(f.GetIntSlice(".id"), 4)
m["fruits"] = append(f.GetStringSlice(".fruits"), "melon")
fmt.Println(m) // map[fruits:[apple banana melon] ids:[1 2 3 4]]
}
Loading
2 참고[ | ]
편집자 Jmnote
로그인하시면 댓글을 쓸 수 있습니다.