mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2025-12-31 18:19:32 -05:00
Bumps [github.com/gookit/config/v2](https://github.com/gookit/config) from 2.2.6 to 2.2.7. - [Release notes](https://github.com/gookit/config/releases) - [Commits](https://github.com/gookit/config/compare/v2.2.6...v2.2.7) --- updated-dependencies: - dependency-name: github.com/gookit/config/v2 dependency-version: 2.2.7 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com>
Map Utils
maputil provide map data util functions. eg: convert, sub-value get, simple merge
- use
map[string]anyas Data - deep get value by key path
- deep set value by key path
Install
go get github.com/gookit/goutil/maputil
Go docs
Usage
Deep get value
mp := map[string]any {
"top1": "val1",
"arr1": []string{"ab", "cd"}
"map1": map[string]any{
"sub1": "val2",
},
}
fmt.Println(maputil.DeepGet(mp, "map1.sub1")) // Output: VAL3
// get value from slice.
fmt.Println(maputil.DeepGet(mp, "arr1.1")) // Output: cd
fmt.Println(maputil.DeepGet(mp, "arr1[1]")) // Output: cd
Deep set value
mp := map[string]any {
"top1": "val1",
"arr1": []string{"ab"}
"map1": map[string]any{
"sub1": "val2",
},
}
err := maputil.SetByPath(&mp, "map1.newKey", "VAL3")
fmt.Println(maputil.DeepGet(mp, "map1.newKey")) // Output: VAL3
Code Check & Testing
gofmt -w -l ./
golint ./...
Testing:
go test -v ./maputil/...
Test limit by regexp:
go test -v -run ^TestSetByKeys ./maputil/...