I have this code in a router handler
decoder := json.NewDecoder(r.Body)
var t person.Model
err := decoder.Decode(&t). // t is a struct value
item, ok := v.People[params["id"]]. // ok is a struct value
if t.Handle != "" {
item.Handle = t.Handle
}
if t.Work != "" {
item.Work = t.Work
}
if t.Image != "" {
item.Image = t.Image
}
if t.Firstname != "" {
item.Firstname = t.Firstname
}
if t.Lastname != "" {
item.Lastname = t.Lastname
}
if t.Email != "" {
item.Email = t.Email
}
But I would like to make this dynamic, something like this:
["Handle", "Work", "Image", "Firstname", "Lastname", "Email"].forEach(v => {
if t[v] != "" {
item[v] = t[v]
}
});
is this possible with Golang somehow?