After thinking about this for a while, it falls into the duh category. This is due to the nature of interfaces in Go, which are link objects that point to other things. I explicitly announced that my map would be map[string]interface{} , which means that the value at the location of each key is interface{} , not a string, so I really shouldn't be surprised to get a reflect.Value that contains an interface{} .
Additional reflect.ValueOf() one level deeper to get the base value of interface{} . I created two examples, both of which, I believe, confirm this behavior.
map[string]Stringer user interface example: http://play.golang.org/p/zXCn9Fce3Q
package main import "fmt" import "reflect" type Test struct { Data string } func (t Test) GetData() string { return t.Data } type Stringer interface { GetData() string } func main() { test := map[string]Stringer{"First": Test{Data: "testing"}} Pass(test) } func Pass(d interface{}) { mydata := reflect.ValueOf(d).MapIndex(reflect.ValueOf("First")) fmt.Printf("Value: %+v \n", mydata.Interface()) fmt.Printf("Kind: %+v \n", mydata.Kind()) fmt.Printf("Kind2: %+v \n", reflect.ValueOf(mydata.Interface()).Kind()) }
returns
Value: {Data:testing} Kind: interface Kind2: struct
Example using map[string]string : http://play.golang.org/p/vXuPzmObgN
package main import "fmt" import "reflect" func main() { test := map[string]string{"First": "firstValue"} Pass(test) } func Pass(d interface{}) { mydata := reflect.ValueOf(d).MapIndex(reflect.ValueOf("First")) fmt.Printf("Value: %+v \n", mydata.Interface()) fmt.Printf("Kind: %+v \n", mydata.Kind()) fmt.Printf("Kind2: %+v \n", reflect.ValueOf(mydata.Interface()).Kind()) }
returns
Value: firstValue Kind: string Kind2: string
source share