On 10 July 2013 13:47, Louisa Berger wrote:
This is not just a map of strings : I don't want ints or the like
converted to strings.
Does anyone know how to check if an interface field is either a string or
any kind of (type X string) ?
This is not just a map of strings : I don't want ints or the like
converted to strings.
Does anyone know how to check if an interface field is either a string or
any kind of (type X string) ?
types like A whose underlying type is string, and you don't know them a
priori?
In that case use reflection:
m := map[string]interface{}{"a" : A("string field")}
m2 := make(map[string]interface{}{"a" : "string field"})
for k, v := range m {
if reflect.TypeOf(v).Kind() == reflect.String {
m2[k] = string(v)
} else {
m2[k] = v
}
}
--
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.