Search⌘ K

Structs, Interfaces and Maps

Explore how to define and initialize structs, test interface implementations, classify types dynamically, and manage maps in Go. This lesson helps you understand key Go data structures and techniques for organizing and manipulating data effectively.

📝 Useful code snippets for structs

Creation

type struct1 struct {
  field1 type1
  field2 type2
  ...
}

ms := new(struct1)

Initialization

ms := &struct1{10, 15.5, "Chris"}

Capitalize the first letter of the struct name to make it visible outside its package. Often, it is better to define a factory function for the struct and force using that.

 ...