See: Golang Cheatsheet
Benefits
- Statically typed — fewer runtime bugs
- Fast builds, fast feedback loop
- Small binaries and containers — quick deploys, low memory usage
- Simple, explicit code; minimal magic
- Strong standard library — particularly for networking and HTTP
Shortcomings
Concurrency
- Goroutines, channels,
select sync.Mutex,sync.RWMutex,sync.WaitGroup- Buffered vs unbuffered channels
- Production concurrency
- Context —
context.WithTimeout,context.WithCancel,context.WithoutCancel
HTTP / API Frameworks
- The standard library covers most needs (
net/http,http.ServeMux) - chi —
net/http-compatible router, idiomatic, well maintained - Echo — fuller framework if needed
JSON
- Use
json.Unmarshalfor one object,json.Decoderfor a stream
Logging
- Use structured logging (slog in stdlib) to reduce allocations
- Add contextual fields (request ID, user, operation)
Testing
- testify — assertions
assertcontinues on failurerequirestops the test on failure
- httpexpect — API tests
- Run with
-raceto catch data races
Gotchas
- A map only grows, it never shrinks — recreate if memory matters (100 Go mistakes)
rangeproduces a copy- Avoid
init() - Slowloris / RUDY — set read and write timeouts on HTTP servers
- Define interfaces on the caller side, not the implementation side
- Slice gotchas
- Does Go have subtyping?
Compiling
- Statically linking Go
- Static Go
- cgo
- Consider goreleaser for release automation