Skip to content

happysnaker/go-service-starter

Repository files navigation

go-service-starter

Go Version License Stars Use this template Project Page Support Async Review

A minimal but production-minded Go HTTP service starter for backend engineers who want a clean service baseline without adopting a heavyweight framework.

This repo is intentionally small enough to understand in one sitting, but structured enough to feel like the beginning of a real internal service.

Why this starter exists

Many Go starter repos fall into one of two buckets:

  • they are too tiny to reuse outside a tutorial
  • they ship so much scaffolding that you are effectively adopting a framework

go-service-starter aims for a middle ground:

  • standard-library first
  • clear service boundaries
  • sane operational defaults
  • easy to extend for real backend work

What you get

  • HTTP server based on net/http
  • environment-based configuration loading
  • structured JSON logging with log/slog
  • healthz, readyz, and version endpoints
  • graceful shutdown on SIGINT / SIGTERM
  • build metadata placeholders for versioned delivery
  • lightweight layout for internal APIs and small services

Architecture at a glance

flowchart LR
    Env["Environment variables"] --> Config["internal/config"]
    Config --> Main["cmd/api/main.go"]
    Main --> Server["internal/httpserver"]
    Build["internal/buildinfo"] --> Server
    Server --> Routes["/, /healthz, /readyz, /version"]
    Server --> Logs["structured request logs"]
Loading

See also: docs/architecture.md

Project layout

cmd/api/                    service entrypoint
internal/config/            env config loading and defaults
internal/httpserver/        routes, server wiring, request logging
internal/buildinfo/         version / commit / builtAt placeholders
configs/service.env.example example local env file
docs/                       architecture and hardening notes
Dockerfile                  minimal container build
Makefile                    common local commands

Endpoints

Endpoint Purpose
GET / basic service response
GET /healthz liveness signal
GET /readyz readiness signal
GET /version build metadata placeholder

Quick start

cp configs/service.env.example .env
set -a && source .env && set +a
go run ./cmd/api

Then hit the service:

curl http://localhost:8080/
curl http://localhost:8080/healthz
curl http://localhost:8080/readyz
curl http://localhost:8080/version

Docker

docker build -t go-service-starter:dev .
docker run --rm -p 8080:8080 --env-file configs/service.env.example go-service-starter:dev

When to use this

This starter is a good fit when you want:

  • a clean baseline for a small backend service
  • a teaching repo for Go service structure
  • a lightweight internal API template
  • a foundation you can grow into metrics, tracing, auth, and persistence

It is not trying to be:

  • a batteries-included platform framework
  • a complete microservice platform
  • an opinionated replacement for your whole internal stack

Production hardening roadmap

Good next additions for a serious service:

  • request IDs and panic recovery middleware
  • metrics / tracing / pprof endpoints
  • configuration validation and startup checks
  • authn / authz middleware
  • persistence wiring and dependency boundaries
  • background workers and drain handling
  • CI, releases, and deployment manifests

See docs/production-hardening.md for a more complete checklist.

Related repos

If you like this repo, you may also want:

Support

If this starter saves you time, consider:

If this starter saved you setup time for a new service, small direct support is especially helpful.

Typical thank-you support amounts that fit this repo:

License

MIT

About

Template-ready minimal production-minded Go HTTP service starter with config loading, structured logging, health endpoints, graceful shutdown, Docker, and reusable docs.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages