Your code can panic.  Take a look at:

https://play.golang.org/p/MrPtar9oEK

traverse2 has the type assertion.  Notice how the call to traverse2 works
but the following call to traverse panics.

    -Paul

On Sun, Feb 12, 2017 at 12:06 PM, John Feminella <[email protected]> wrote:

> Thanks. I wound up doing this with a recursive traversal:
>
> https://play.golang.org/p/k9iy3sHOZ9
>
> best,
> ~ jf
> --
> John Feminella
> @jxxf
> http://jxf.me
>
>
>
> On Sun, Feb 12, 2017 3:05 PM, Paul Borman [email protected] wrote:
>
>> 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, <[email protected]> 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 [email protected].
>> 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 [email protected].
For more options, visit https://groups.google.com/d/optout.

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

Reply via email to