To create a struct in Go, you use the type
keyword followed by the name of the struct and its definition using curly braces. Here's an example:
main.go83 chars6 lines
In this example, we've created a struct named Person
with three properties: FirstName
, LastName
, and Age
. Each property has its own data type.
To use this struct, you can create a new instance of it like this:
main.go57 chars2 lines
You can then access the properties of the struct using dot notation like this:
main.go120 chars4 lines
Structs are a powerful way to group related data together in Go.
gistlibby LogSnag