To create a struct in Go with a field of type bool, define the struct type and add a field with the bool type as follows:
main.go46 chars4 lines
Here, MyStruct
is the name of the struct, and myBoolField
is the name of the bool field within MyStruct
.
You can then create an instance of MyStruct
and set myBoolField
using the following code:
main.go40 chars2 lines
or
main.go51 chars3 lines
Here, myStruct
is an instance of MyStruct
with myBoolField
set to true
.
gistlibby LogSnag