This is a minimal web application written in Go using:
- Gorilla Mux for HTTP routing
- SQLite (pure Go driver) for persistence
It exposes a tiny API to manage a list of items and demonstrates a straightforward project structure.
- Healthcheck endpoint
- Create an item
- List items
- Auto-create the SQLite database and schema if missing
- Graceful shutdown
- Go 1.20+ (tested with Go 1.22). The
go.modmay state a newer version but the code uses standard features. - No CGO required (uses
modernc.org/sqlitepure-Go driver)
web_app/
README.md
go.mod
main.go
internal/
db/
db.go # DB connection + schema migration
handlers/
handlers.go # HTTP handlers (health, items)
models/
item.go # Data model
From the web_app directory:
# Fetch dependencies
go mod tidy
# Run
go run ./...By default the server listens on :8080 and creates a SQLite database at data/app.db.
You can override defaults via environment variables:
PORT: server port (default8080)DB_PATH: sqlite database file path (defaultdata/app.db)
-
Health
GET /health->{ "status": "ok" }
-
List items
GET /items->[{ "id": 1, "name": "foo", "created_at": "2025-01-01T00:00:00Z" }]
-
Create item
POST /items- Content-Type: application/json
- Body:
{ "name": "my item" } - Response:
201 Createdwith the created item JSON
# Health
curl -s http://localhost:8080/health | jq
# Create
curl -s -X POST http://localhost:8080/items \
-H 'Content-Type: application/json' \
-d '{"name":"first"}' | jq
# List
curl -s http://localhost:8080/items | jq- The database schema is created on startup if it does not exist.
- Errors are returned with appropriate HTTP status codes and JSON messages.
- The code is intentionally minimal and well-commented for learning purposes.