A simple Users API built with Go's standard library — no frameworks, no external dependencies. Built as a learning project to understand HTTP servers, middleware, and concurrency in Go.
Full CRUD API for managing users, built entirely with Go's net/http package. Uses an in-memory store with sync.RWMutex for safe concurrent access, a logger middleware that tracks request duration, email validation and duplicate detection, and graceful shutdown on SIGINT/SIGTERM.
POST /users
Body:
{
"name": "John Doe",
"email": "john@example.com"
}Response: 201 Created
{
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"created_at": "2026-02-25T13:00:00Z"
}GET /users
Response: 200 OK
[
{
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"created_at": "2026-02-25T13:00:00Z"
}
]GET /users/{id}
Response: 200 OK or 404 Not Found
PATCH /users/{id}
Body: (all fields optional)
{
"name": "Jane Doe",
"email": "jane@example.com"
}Response: 200 OK with updated user
DELETE /users/{id}
Response: 204 No Content
All errors return a JSON body:
{
"error": "user not found"
}Common error codes: 400 Bad Request, 404 Not Found, 409 Conflict
users-api/
├── main.go # Everything lives here — handlers, middleware, server setup
└── go.mod # Module definition
Since this is a learning project, everything is intentionally kept in a single file for readability. A production version would split handlers, middleware, and the store into separate packages.