How to set bool pointer to true in struct literal?
问题 I have the function below which accepts a bool pointer. I'm wondering if there is any notation which allows me to set the value of the is field to true in the struct literal; basically without to define a new identifier (i.e. var x := true ; handler{is: &x} ) package main import "fmt" func main() { fmt.Println("Hello, playground") check(handler{is: new(bool) }) } type handler struct{ is *bool } func check(is handler){} 回答1: You can do that but it's not optimal: h := handler{is: &[]bool{true}