jeudi 15 février 2018

Reflection of dynamic types

I want to write a Go function that takes a map and a structType and builds using reflection a struct instance based on received map.

    func BuildFromReflection(m map[string]interface{}, structType interface{}) {
        customType := reflect.ValueOf(structType).Type()
        var result customType
        ...
}

I call the function like this:

Utils.BuildFromReflection(m, User{})

But I receive this error:

customType is not a type





Aucun commentaire:

Enregistrer un commentaire