This is a GitHub template. Click "Use this template" at the top of the repo (or the badge above) to spin up a fresh service. See Use this template below for the one-command rename.
Minimal Go HTTP server template. See docs at gultekinmakif.github.io/go-http-server.
Standard library net/http with:
- Go 1.22+ method-prefix routing
- middleware: request ID, request logger, panic recoverer
- DB: Postgres + GORM
- Docker: multi-stage, distroless
- env: typed config, validated at startup
- logs:
slog— tint in dev, JSON in prod - graceful shutdown on SIGINT/SIGTERM
-
Create a new repo from this template (or click "Use this template" in the UI):
gh repo create my-go-server --template gultekinmakif/go-http-server --private --clone cd my-go-server -
Rename the module path + DB name + Docker tag:
./scripts/init-template.sh github.com/<you>/my-go-server go mod tidy
-
Replace
@gultekinmakifin .github/CODEOWNERS with your handle -
Import the branch-protection ruleset (one-time, per repo):
sed -i '' 's/@gultekinmakif/@<your-handle>/' .github/CODEOWNERS gh api --method POST -H "Accept: application/vnd.github+json" \ "repos/<you>/<repo>/rulesets" \ --input <(jq 'del(.id, .source, .source_type)' .github/rulesets/pr-protection.json)
After that, make docker-up and you're running.
docker compose up --build # app + postgres on :3000
curl localhost:3000/healthOr against your own Postgres:
cp configs/.env.example .env
make run
make dev # hot-reload
make help| Method | Path | Notes |
|---|---|---|
GET |
/health |
Liveness -> {"status":"ok"} |
POST |
/posts |
Create. Body: {title, body, slug}. Returns 201 + record. |
GET |
/posts |
List all posts |
GET |
/posts/{slug} |
Read by slug. 404 on miss. |
See docs at gultekinmakif.github.io/go-http-server.
| Var | Default | Notes |
|---|---|---|
PORT |
3000 |
|
ENV |
dev |
dev → tint pretty logs, prod → JSON |
LOG_LEVEL |
debug |
debug / info / warn / error |
SHUTDOWN_TIMEOUT |
10s |
Graceful drain timeout |
DATABASE_URL |
(required) | Postgres DSN, e.g. postgres://postgres:postgres@localhost:5432/http_server?sslmode=disable |
see LICENSE.