Go's standard library is enough to build a cloud-native service: net/http for APIs and clients, encoding/json for payloads, context for timeouts and cancellation, log/slog for structured logs, os/signal for graceful shutdown and crypto/tls for secure transport. The cloud provider SDKs are separate modules, but the patterns around them (health checks, config from environment variables, retries and shutdown) are all standard library.
The sections below build up a small service that is ready for a container platform such as Kubernetes or a managed container service.
net/httpnet/httpSince Go 1.22 the default http.ServeMux supports methods and path parameters in patterns, so a small API needs no router package.
The GET /items/{id} pattern matches only GET requests, and r.PathValue("id") returns the matched segment. Cloud load balancers and orchestrators call a health endpoint like /healthz to decide whether to send traffic to an instance, so always expose one.
http.ListenAndServe has no timeouts, which leaves the service open to slow-client attacks. Create an http.Server and set them explicitly. Read configuration from environment variables, the usual way cloud platforms inject settings.
Many platforms provide the listening port through a PORT variable, so reading it keeps the same binary portable across environments.
Orchestrators stop containers by sending SIGTERM. A graceful shutdown finishes in-flight requests before exiting.
This reuses newServer from the previous section. signal.NotifyContext cancels the context when a signal arrives, and Shutdown stops accepting new connections while existing requests finish within the timeout. The log/slog package (Go 1.21+) writes JSON logs that cloud logging systems parse directly.
The default http.Client has no timeout. Always set one, and pass a context per request.
Reuse one client so connections are pooled, check the status code, close the body and cap the amount you read. For transient failures such as 503, add retries with exponential backoff and jitter, and only retry idempotent requests.
| Need | Standard library | Typically external |
|---|---|---|
| HTTP server and client, TLS | net/http, crypto/tls | HTTP/3 (QUIC) |
| Structured logging | log/slog | Log shipping agents |
| Metrics and tracing | expvar (basic) | Prometheus client, OpenTelemetry |
| Object storage, queues, managed databases | database/sql (interface only) | Provider SDKs and drivers |
| gRPC | none | google.golang.org/grpc |
Use the provider's official Go SDK for services such as object storage or message queues, and keep the surrounding service code on the standard library.
Yes. It compiles to a single static binary, starts quickly, uses little memory and has strong concurrency, which suits containers and serverless platforms.
Not usually. Since Go 1.22 http.ServeMux handles methods and path parameters. Add a router only if you need features beyond that.
Read environment variables with os.LookupEnv and validate them at startup. Keep secrets in the platform's secret store, not in the image.
It probably exits on SIGTERM without calling Server.Shutdown. Add graceful shutdown and a readiness endpoint so traffic drains first.
Build cloud services in Go with net/http and the Go 1.22 ServeMux patterns, explicit server timeouts, environment-based configuration, slog logging and graceful shutdown on SIGTERM. Use a shared http.Client with timeouts and contexts for outbound calls, and reach for provider SDKs, OpenTelemetry or gRPC only where the standard library stops.