FAQ
I want to be able to normalize the data in a map[string]interface{}.

So if I have a type

type A string

I want to be able to convert an instance of A in a map to a string.

So if I have something like m := map[string]interface{}{"a" : A("string
field")}

I want to be able to convert it to map[string]interface{}{"a" : "string
field"}

However, I do not want to use something like fmt.Sprintf("%v", m["a"]),
because I don't want ints or the like converted to strings.

Using reflection I'm able to go through and change each field, but since
the map is map[string]*interface{}*, I can't get the type of m["a"]
(reflect.TypeOf(m["a"]) and reflect.TypeOf(m["a"]).Kind() ==
reflect.Interface ).

Does anyone know how to check if an interface field is either a string or
any kind of (type X string) ?

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 6 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJul 10, '13 at 2:42a
activeJul 11, '13 at 7:42a
posts6
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase