Go structs
A struct is a user-defined type that groups named fields into one value. Structs are commonly used to represent domain objects such as users, orders, and rate-limiter state.
Minimal example
type Bucket struct {
Capacity int
Tokens int
}
func main() {
bucket := Bucket{Capacity: 10, Tokens: 10}
fmt.Println(bucket.Tokens)
}Learn this concept
Lesson 1.5 · Structs, pointers, slices and mapsUsed in exercises
Exercise 1.8 · Practice: write your first Go program Exercise 1.11 · Token bucket limiter with lazy refill Exercise 1.14 · Limiter interface and a FixedWindow implementation Exercise 1.15 · Table-driven tests with a fake clock, plus one race test Exercise 1.22 · Redis fixed-window limiter that fails open Exercise 1.26 · Optional: Sliding window log limiter Exercise 1.27 · Optional: Sliding window counter limiter Exercise 1.28 · Optional: Leaky bucket limiter Exercise 2.22 · GET /v1/restaurants: signed cursors Exercise 8.15 · Latency percentile packagePrerequisite conceptsGo functions