I’m very new in Go. I was wondering how do I get value of mappings out of this using Reflection in Go.
type url_mappings struct{
mappings map[string]string
}
func init() {
var url url_mappings
url.mappings = map[string]string{
"url": "/",
"controller": "hello"}
Thanks
mappings‘s type is interface{}, so you can’t use it as a map.To have the real
mappingsthat it’s type ismap[string]string, you’ll need to use some type assertion:Because of the repeating
map[string]string, I would:And then you can: