How do I set the referenced value of a string pointer in a type to the empty string? Consider this example:
package main
import (
"fmt"
)
type Test struct {
value *string
}
func main() {
t := Test{nil}
if t.value == nil {
// I want to set the pointer's value to the empty string here
}
fmt.Println(t.value)
}
&*
t.value = &""
t.value = *""
&t.value = ""
*t.value = ""
reflectSetString
reflect.ValueOf(t.value).SetString("")
and this gives a compilation error
panic: reflect: reflect.Value.SetString using unaddressable value
I'm assuming that's because strings in Go are immutable?