papa-carlo - Struct Builder for Go
Struct initialization in Go is simple, but enforcing mandatory fields can quickly become tricky in larger codebases. Let’s walk through the problem and explore a possible solution. Named field initialization One common way to create struct instances is by specifying fields by name. type Vertex struct { X int Y int } fmt.Println(Vertex{X: 1, Y: 2}) // {1 2} This allows us to omit fields at creation time, which will make Go fall back to the default value for the omitted fields: ...