Skip to main content

Claude/ChatGPT Prompt to Generate a Production-Ready Go HTTP Server Template

Scaffold a production Go HTTP server with structured logging, graceful shutdown, middleware, health checks, and a Dockerfile.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt

                                

What this prompt does

This prompt scaffolds a production-ready Go HTTP server with the boring-but-critical infrastructure already wired in. It frames the model as a senior Go engineer who favors the standard library and returns idiomatic, working Go. It asks for six deliverables: a main.go with sensible server timeouts, structured JSON logging via slog with a request-scoped logger, graceful shutdown on SIGTERM/SIGINT, a middleware chain, health and readiness endpoints, and env-based config plus a multi-stage Dockerfile.

Four variables tailor the scaffold. [service_name] names the service and the Docker image. [router_choice] selects the router or mux the middleware chain is built on. [port] is where the server listens with proper read, write, and idle timeouts. [log_level] sets the default slog level. The emphasis is on getting graceful shutdown right first, because killed-mid-request is the bug nobody reproduces locally — exactly the kind of production gap a solid template closes. Starting every service from the same scaffold also means logging, health checks, and recovery behave identically across your fleet, which pays off the moment you're debugging one at 2am.

When to use it

  • You're standing up a new Go service and want it production-shaped from day one
  • You keep skipping shutdown, recovery, and health checks and getting bitten later
  • You want structured JSON logging with a request-scoped logger out of the box
  • You need /healthz and /readyz endpoints with a real readiness check
  • You want a multi-stage Dockerfile for a small final image
  • You want a consistent template every new service starts from

Example output

You get the full file tree and each file's contents: a main.go starting the server on your port with read/write/idle timeouts, slog-based structured JSON logging at your log level with a request-scoped logger, graceful shutdown on SIGTERM/SIGINT that drains in-flight requests with a deadline, a middleware chain on your chosen router with request ID, panic recovery, and request metrics, /healthz and /readyz endpoints with a real readiness check, env-based config with defaults, and a multi-stage Dockerfile.

Pro tips

  • Get graceful shutdown right first; killed-mid-request is the bug nobody reproduces locally, and the deadline on draining in-flight requests is the safeguard
  • Pick [router_choice] to match your team's convention; the prompt favors the standard library, so a light router like chi keeps things idiomatic
  • Replace the readiness check placeholder with a real dependency ping (DB, cache) before relying on /readyz in production
  • Set [log_level] to info for production and switch to debug only when investigating, so logs stay readable
  • Keep [service_name] consistent across the binary, logs, and Docker image for clean observability
  • Confirm the timeouts on [port] suit your traffic; defaults are sensible starting points, not universal truths

Frequently Asked Questions

Which router does it use?
Whatever you set in `[router_choice]`, with the prompt favoring the standard library first. A lightweight router like chi keeps the middleware chain idiomatic while still giving you request IDs, panic recovery, and metrics.
Is the readiness check production-ready as generated?
It includes a real readiness check structure with a dependency ping placeholder, such as a DB ping. You must wire in your actual dependencies before trusting /readyz, since the placeholder does not verify your real services on its own.
Why is graceful shutdown emphasized so much?
Because killed-mid-request is a production bug that almost never reproduces locally. The shutdown logic drains in-flight requests with a deadline on SIGTERM/SIGINT, which prevents dropped requests during deploys and restarts.
Does it include a Dockerfile?
Yes, a multi-stage Dockerfile for your `[service_name]`, which produces a small final image by separating the build stage from the runtime. You may still want to adjust the base image or add your own build flags.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in Rust & Go Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support