Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/deatil/go-array
A Go package that read or set data from map, slice or json
https://github.com/deatil/go-array
array go go-array map slice
Last synced: about 2 months ago
JSON representation
A Go package that read or set data from map, slice or json
- Host: GitHub
- URL: https://github.com/deatil/go-array
- Owner: deatil
- License: apache-2.0
- Created: 2022-08-03T11:54:39.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-20T04:06:00.000Z (8 months ago)
- Last Synced: 2024-10-12T11:27:52.010Z (2 months ago)
- Topics: array, go, go-array, map, slice
- Language: Go
- Homepage: https://pkg.go.dev/github.com/deatil/go-array
- Size: 49.8 KB
- Stars: 19
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - go-array - A Go package that read or set data from map, slice or json. (Configuration / Standard CLI)
- fucking-awesome-go - go-array - A Go package that read or set data from map, slice or json. (Configuration / Standard CLI)
- awesome-go - go-array - A Go package that read or set data from map, slice or json. (Configuration / Standard CLI)
- awesome-go-with-stars - go-array - A Go package that read or set data from map, slice or json. (Configuration / Standard CLI)
- awesome-go-cn - go-array - array) [![包含中文文档][CN]](https://github.com/deatil/go-array) (配置 / 标准CLI)
- awesome-go-plus - go-array - A Go package that read or set data from map, slice or json. ![stars](https://img.shields.io/badge/stars-20-blue) (Configuration / Standard CLI)
- awesome-go-plus - go-array - A Go package that read or set data from map, slice or json. ![stars](https://img.shields.io/badge/stars-19-blue) ![forks](https://img.shields.io/badge/forks-0-blue) (Configuration / Standard CLI)
README
## go-array
A Go package that read or set data from map, slice or json[中文](README_CN.md) | English
### Download
~~~go
go get -u github.com/deatil/go-array
~~~### Get Starting
~~~go
import "github.com/deatil/go-array/array"arrData := map[string]any{
"a": 123,
"b": map[string]any{
"c": "ccc",
"d": map[string]any{
"e": "eee",
"f": map[string]any{
"g": "ggg",
},
},
"dd": []any{
"ccccc",
"ddddd",
"fffff",
},
"ff": map[any]any{
111: "fccccc",
222: "fddddd",
333: "dfffff",
},
"hh": map[int]any{
1115: "hccccc",
2225: "hddddd",
3335: map[any]string{
"qq1": "qq1ccccc",
"qq2": "qq2ddddd",
"qq3": "qq3fffff",
},
},
"kJh21ay": map[string]any{
"Hjk2": "fccDcc",
"23rt": "^hgcF5c",
},
},
}data := array.Get(arrData, "b.d.e")
// output: eeedata := array.Get(arrData, "b.dd.1")
// output: ddddddata := array.Get(arrData, "b.hh.3335.qq2")
// output: qq2ddddddata := array.Get(arrData, "b.kJh21ay.Hjk2", "defValString")
// output: fccDccdata := array.Get(arrData, "b.kJh21ay.Hjk23333", "defValString")
// output: defValString
~~~### Examples
* Exists data
~~~go
var res bool = array.New(arrData).Exists("b.kJh21ay.Hjk2")
// output: truevar res bool = array.New(arrData).Exists("b.kJh21ay.Hjk12")
// output: false
~~~* Get data
~~~go
var res any = array.New(arrData).Get("b.kJh21ay.Hjk2")
// output: fccDccvar res any = array.New(arrData).Get("b.kJh21ay.Hjk12", "defVal")
// output: defVal
~~~* Find data
~~~go
var res any = array.New(arrData).Find("b.kJh21ay.Hjk2")
// output: fccDccvar res any = array.New(arrData).Find("b.kJh21ay.Hjk12")
// output: nil
~~~* Use Sub to Find data
~~~go
var res any = array.New(arrData).Sub("b.kJh21ay.Hjk2").Value()
// output: fccDccvar res any = array.New(arrData).Sub("b.kJh21ay.Hjk12").Value()
// output: nil
~~~* Use Search to Find data
~~~go
var res any = array.New(arrData).Search("b", "kJh21ay", "Hjk2").Value()
// output: fccDccvar res any = array.New(arrData).Search("b", "kJh21ay", "Hjk12").Value()
// output: nil
~~~* Use Index to Find data
~~~go
var res any = array.New(arrData).Sub("b.dd").Index(1).Value()
// output: dddddvar res any = array.New(arrData).Sub("b.dd").Index(6).Value()
// output: nil
~~~* Use Set to set data
~~~go
arr, err := array.New(arrData).Set("qqqyyy", "b", "ff", 222)
// arr.Get("b.ff.222") output: qqqyyy
~~~* Use SetIndex to set data
~~~go
arr, err := array.New(arrData).Sub("b.dd").SetIndex("qqqyyySetIndex", 1)
// arr.Get("b.dd.1") output: qqqyyySetIndex
~~~* Use Delete to delete data
~~~go
arr, err := array.New(arrData).Delete("b", "hh", 2225)
// arr.Get("b.hh.2225") output: nil
~~~* Use DeleteKey to delete data
~~~go
arr, err := array.New(arrData).DeleteKey("b.d.e")
// arr.Get("b.d.e") output: nil
~~~### LICENSE
* The library LICENSE is `Apache2`, using the library need keep the LICENSE.
### Copyright
* Copyright deatil(https://github.com/deatil).