Production'da Go: 10 pratik ipucu

Context, graceful shutdown, loglama ve gözlemlenebilirlik.

Çalışan demo üretim değildir. GoDev Türkiye’nin kısa kontrol listesi:

  1. context.Context’i isteğin kökünden aşağı taşı.
  2. Graceful shutdown: signal.Notify + server.Shutdown.
  3. Yapılandırılmış log (log/slog).
  4. -race ile CI’da test et.
  5. Timeout’suz HTTP client kullanma.
  6. Health / ready endpoint’leri ayır.
  7. Secret’ları koda gömme.
  8. Metric: latency, error rate, goroutine sayısı.
  9. Migration’ları bilinçli yönet.
  10. Küçük interface + net paket sınırları.
go
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()
<-ctx.Done()
shutdownCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
server.Shutdown(shutdownCtx)

← Tüm blog