To create a struct with a field of type int in Go, we can define a new type with the type keyword followed by the struct name and its fields.
main.go44 chars4 lines
In the example above, we defined a new struct named MyStruct with a single field called myIntField of type int. Now we can create a new instance of the MyStruct struct and set its myIntField field:
main.go37 chars2 lines
In this second example, we created a new instance of MyStruct and set its myIntField field to the value 42.
gistlibby LogSnag