I have a JSON struct of the following form:
type postJSON struct {
ButtonA *bool `json:"button_a,omitempty"`
ButtonB *bool `json:"button_b,omitempty"`
}
This allows me to omit false from a sent message, i.e. only true values are sent.
I currently have to setup a (package) variable like this:
var pressed = new(bool)
...
post_json := postJSON{}
if strings.Contains(msg, "a") {
post_json.ButtonA = pressed
}
...
func init() {
*pressed = true
}
Are there better ways to setup pressed - or to do this? I’m really looking for something like:
post_json.ButtonA = &true
N.B. I do not want to create (make) a new true pointer to boolean every time - so making it and assigning it would not be (I think) a good solution.
Thank you - Andy