struct
A Go type that groups named fields of different types into one value, such as a Target with a Name and a Port.
In more detail
Structs are how Go models data: configuration, targets, results and reports. Fields are accessed with a dot, as in t.Port, and methods can be attached to the type. A zero struct has every field at its zero value and is often ready to use.
Example
type Target struct {
Name string
Port int
}Related terms
- struct field — One named value inside a struct, such as Name or Port, with its own type.
- 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}.
- method — A function that belongs to an object or type and is called on a value of it, as in name.upper().
- struct tag — A string in backquotes after a struct field, such as `json:"status"`, that tells encoders like encoding/json how to name or treat that field.
- 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
- Go Workspaces and Modules — Concurrent Systems Programming with Go
- Your First Program and go run — Concurrent Systems Programming with Go
- Variables, Typing, and Zero Values — Concurrent Systems Programming with Go
- Structs and Methods — Concurrent Systems Programming with Go
- Interfaces and Why They Are Implicit — Concurrent Systems Programming with Go
- Type Assertions and the Empty Interface — Concurrent Systems Programming with Go
- Parsing JSON with encoding/json — Concurrent Systems Programming with Go
- Project Setup and Configuration — Concurrent Systems Programming with Go