ProductPromotion
Logo

Go.Lang

made by https://0x3d.site

GitHub - deatil/go-array: A Go package that read or set data from map, slice or json
A Go package that read or set data from map, slice or json - deatil/go-array
Visit Site

GitHub - deatil/go-array: A Go package that read or set data from map, slice or json

GitHub - deatil/go-array: A Go package that read or set data from map, slice or json

go-array

中文 | English

Download

go get -u github.com/deatil/go-array

Get Starting

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: eee

data := array.Get(arrData, "b.dd.1")
// output: ddddd

data := array.Get(arrData, "b.hh.3335.qq2")
// output: qq2ddddd

data := array.Get(arrData, "b.kJh21ay.Hjk2", "defValString")
// output: fccDcc

data := array.Get(arrData, "b.kJh21ay.Hjk23333", "defValString")
// output: defValString

Examples

  • Exists data
var res bool = array.New(arrData).Exists("b.kJh21ay.Hjk2")
// output: true

var res bool = array.New(arrData).Exists("b.kJh21ay.Hjk12")
// output: false
  • Get data
var res any = array.New(arrData).Get("b.kJh21ay.Hjk2")
// output: fccDcc

var res any = array.New(arrData).Get("b.kJh21ay.Hjk12", "defVal")
// output: defVal
  • Find data
var res any = array.New(arrData).Find("b.kJh21ay.Hjk2")
// output: fccDcc

var res any = array.New(arrData).Find("b.kJh21ay.Hjk12")
// output: nil
  • Use Sub to Find data
var res any = array.New(arrData).Sub("b.kJh21ay.Hjk2").Value()
// output: fccDcc

var res any = array.New(arrData).Sub("b.kJh21ay.Hjk12").Value()
// output: nil
  • Use Search to Find data
var res any = array.New(arrData).Search("b", "kJh21ay", "Hjk2").Value()
// output: fccDcc

var res any = array.New(arrData).Search("b", "kJh21ay", "Hjk12").Value()
// output: nil
  • Use Index to Find data
var res any = array.New(arrData).Sub("b.dd").Index(1).Value()
// output: ddddd

var res any = array.New(arrData).Sub("b.dd").Index(6).Value()
// output: nil
  • Use Set to set data
arr, err := array.New(arrData).Set("qqqyyy", "b", "ff", 222)
// arr.Get("b.ff.222") output: qqqyyy
  • Use SetIndex to set data
arr, err := array.New(arrData).Sub("b.dd").SetIndex("qqqyyySetIndex", 1)
// arr.Get("b.dd.1") output: qqqyyySetIndex
  • Use Delete to delete data
arr, err := array.New(arrData).Delete("b", "hh", 2225)
// arr.Get("b.hh.2225") output: nil
  • Use DeleteKey to delete data
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

Articles
to learn more about the golang concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about GoLang.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory