composite literal
Go syntax that builds a struct, slice or map value in place by listing its contents in braces, such as Target{Name: "api", Port: 8080}.
In more detail
Naming the fields makes construction readable and safe when fields are added later; any field you leave out gets its zero value. Slice and map literals, such as []string{"api", "worker"}, work the same way.
Example
target := Target{Name: "api", Port: 8080}Related terms
- struct — A Go type that groups named fields of different types into one value, such as a Target with a Name and a Port.
- slice — A flexible, growable view over a list of values of one type, written like []string, and Go's everyday list.
- map — A Go collection that stores values by key, such as service name to port number, and looks them up quickly.
- zero value — The value Go gives a variable automatically when you declare it without one: 0 for numbers, "" for strings, false for booleans and nil for pointers, slices and maps.
Taught in
- Structs and Methods — Concurrent Systems Programming with Go