GoServerTemplate

module
v0.0.0-...-3cdb8d2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2026 License: GPL-3.0

README

GoServerTemplate

Go Report Card Go Version License

Production-ready Go server template with layered architecture, dependency injection, and PostgreSQL support.

Architecture

cmd/server         → Application entrypoint (FX bootstrap)
internal/config    → Environment-based configuration
internal/db        → PostgreSQL connection (sqlx + pgx)
internal/handler   → HTTP handlers (handler → service → repo)
internal/service   → Business logic
internal/repository → Data access layer
internal/router    → gorilla/mux routing + middleware
pkg/logger         → Structured logging (slog)

Dependencies

Environment Variables

Variable Default Description
PORT :8080 Server listen address
DB_DSN "" Postgres DSN (optional)
LOG_LEVEL info slog level: debug/info/warn/error

Running Locally

# Run server
go run ./cmd/server

# Run tests
go test ./...

# Build binary
go build -o server ./cmd/server
./server

Docker

docker build -t go-server-template .
docker run -p 8080:8080 -e PORT=:8080 go-server-template

Routes

Method Path Description
GET / Welcome / status
GET /health Health check (DB ping)

Directories

Path Synopsis
cmd
server command
internal
db
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL