Golang Structs are the user-defined type that contains the collection of named fields/properties. It is used to group related data to form a single unit.  Any real-world entity that has the set of properties can be represented using a struct.

Structs are useful for grouping data together to create records.

If you’re coming from the object-oriented programming background, you can think of a struct as the lightweight class that supports the composition but not an inheritance.

Go Structs example

Go struct is a user-defined type that represents the collection of fields.

It can be used in the places where it makes sense to group data into the single unit rather than maintaining each of them as the separate types.

For instance, a student has firstName, lastName, and age. It makes sense to group these three fields into a single structure student.

#golang #golang structs #go

Golang Structs Example | Structs In Go Explained
1.80 GEEK