I'm having a bit of trouble setting a reflect.Value which is a string to something different.
In the follow GetValue() return a reflect.Value
val, err := exp.GetFact(t.(*api.Event_Set).Set.Key).GetValue()
if err != nil {
ref := reflect.Indirect(val)
ref.SetString(t.(*api.Event_Set).Set.Value)
}
Upon hitting SetString it throws a panic:
panic: reflect: reflect.Value.SetString using unaddressable value
I've attempted different syntax ie without an Indirect, with an Elem() etc. How do I correctly change the value of the string?
val?valreflect.Value? The error is that you have an unaddressable value, you cannot make that addressable after the fact.stringand not*string, I think that would be the source of your problem.reflect.Valuewas not a pointer to begin with, there's no meaningful way to turn it into a pointer, because all association with the original "real" value has been lost. (also btw tryval.Type().String())