How to convert interface{} to map

You don’t need reflect here. Try:

v, ok := in.(map[string]*Book)
if !ok {
    // Can't assert, handle error.
}
for _, s := range v {
    fmt.Printf("Value: %v\n", s)
}

Same goes for the rest of your function. It looks like you’re using reflection when you would be better served by a type switch.


Alternatively, if you insist on using reflection here (which doesn’t make a lot of sense) you can also use Value.MapKeys with the result from your ValueOf (see the answer https://stackoverflow.com/a/38186057/714501)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)