Go time package
The Go time package provides types and functions for representing instants, measuring durations, and working with clocks. Rate limiters use time values and durations to calculate when tokens or request allowances become available.
Minimal example
now := time.Now()
window := 30 * time.Second
expiresAt := now.Add(window)
fmt.Println(expiresAt)Learn this concept
Lesson 1.10 · Mutexes and time: making a limiter safe and testableUsed in exercises
Exercise 1.11 · Token bucket limiter with lazy refill Exercise 1.14 · Limiter interface and a FixedWindow implementation Exercise 1.26 · Optional: Sliding window log limiter Exercise 1.27 · Optional: Sliding window counter limiter Exercise 1.28 · Optional: Leaky bucket limiter Exercise 1.30 · Optional: X-RateLimit response headersPrerequisite conceptsGo functions