A pointer has to point to something, which means you have to either assign it to the address of another variable (as in your second example), or initialize it with new()
and then assign by dereference. Personally I'd recommend the former, as new
is not widely used in Go. But, for demonstration:
example := new(bool)
*example = true
https://play.golang.org/p/0VO5jNPMutQ
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…