Use a type assertion to determine if the value is a string
:
for key, value := range m3 {
if s, ok := value.(string); ok {
fmt.Printf("%s is the string %q
", key, s)
} else {
fmt.Printf("%s is not a string
", key)
}
}
Use reflect to determine if the value's base type string:
type mystring string
m3 := map[string]interface{}{
"something": 1,
"brawba": "Bawrbawr",
"foo": mystring("bar"),
}
for key, value := range m3 {
if reflect.ValueOf(value).Kind() == reflect.String {
fmt.Printf("%s is a string with type %T and value %q
", key, value, value)
} else {
fmt.Printf("%s is not a string
", key)
}
}