Take a look at the reflect package, or if you know that the only internal
maps will be of type map[string]interface{} you can use type assertion to
determine if the element is a map or some other type.

On Sun, Feb 12, 2017 at 7:53 AM, <j...@jxf.me> wrote:

> I would like to write a function which, given:
>
>   * a `[]string` keys, and
>   * a `map[string]interface{}` m,
>
> will return the value obtained by traversing `m` for each key in `keys`.
>
> For example, if `m` looks like:
>
>   {
>     "foo": 123,
>     "bar": map[string]interface{}{
>       "one": 111,
>       "two": "222222"
>     },
>   }
>
> then I would like to be able to pass `["bar", "two"]` and receive
> `"222222"`. Similarly I would like to be able to pass ["foo"] and receive
> `123`.
>
> Does this make sense? Is this doable?
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to