If I have a struct as shown below that contains a string pointer, how do I assign or initialize the string pointer?
type foo struct {
strPtr *string
strVal string
}
_ = foo {strVal: "a"} //This works
_ = foo {strPtr: "b"} //This gives me the error: cannot use "b" (type string) as type *string in field value
I am having to use a string pointer type because my struct is being unmarshalled using encoding/json and if the incoming string is null, JSON requires a string pointer to correctly unmarshall the value. I think that JSON is using reflection to populate the string pointer but I want to be able to set and manipulate the string pointer from regular Go code without using reflection. Is this possible and if so, how?
Luke