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
  • Contextcontext.WithTimeout, context.WithCancel, context.WithoutCancel

HTTP / API Frameworks

  • The standard library covers most needs (net/http, http.ServeMux)
  • chinet/http-compatible router, idiomatic, well maintained
  • Echo — fuller framework if needed

JSON

  • Use json.Unmarshal for one object, json.Decoder for a stream

Logging

  • Use structured logging (slog in stdlib) to reduce allocations
  • Add contextual fields (request ID, user, operation)

Testing

  • testify — assertions
    • assert continues on failure
    • require stops the test on failure
  • httpexpect — API tests
  • Run with -race to catch data races

Gotchas

  • A map only grows, it never shrinks — recreate if memory matters (100 Go mistakes)
  • range produces 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

Resources