V
V
Voksel2016-06-17 12:34:12
go
Voksel, 2016-06-17 12:34:12

How to create a heterogeneous multidimensional Golang map?

Good afternoon. Tell me how to declare such a map in Go

["string"][
    "string": int,
    "string1": [
      "string": int,
    ]
    "string2": [
      "string": int,
    ]
    "stringN": [
      "string": int,
    ]
...
  ]

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Kana, 2016-06-18
@kana-desu

https://godoc.org/labix.org/v2/mgo/bson#M
https://godoc.org/github.com/gin-gonic/gin#H

type M map[string]interface{}

obj := M{
  "hello": "world",
  "hello2": []M{
    {"a": 1},
    {"b": 2},
  },
  "c": M{
    "subC": 3,
  },
}

A
Andrey Inishev, 2016-06-17
@inish777

I'm afraid, only something like this
And then unpack from interface {}

N
Nikita, 2016-06-17
@bitver

An example from something

type config map[string]interface{}

cfg := config{
    "id": 123,
    "components": config{
      "user": "asd",
      "db": config{
        "user": "root",
        "pswd": "pass",
      },
    },
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question