You need to pass a pointer to o
to reflect.ValueOf
. By simply passing the value, the fields of the struct will not be addressable.
r := reflect.ValueOf(&o)
f := reflect.Indirect(r).FieldByName("Uid")
f.SetUint(42)
If at all possible, however, I would try to implement this without reflection. Either use a map in your protocol buffer definition, or a switch in your Go code:
switch name {
case "Uid":
o.Uid = uintValue
case "Name"
o.Name = stringValue
}
The non-reflect code is less likely to fail at runtime.