Go server and RESTful API template. Uses only Go's standard library plus github.com/pkg/errors.
make run # go run main.go
make build # compiles to ./mainServer listens on http://localhost:3000.
| Method | Path | Response |
|---|---|---|
| GET | / |
200 OK (empty body) |
| GET | /record |
403 {"message": "forbidden"} |
api/ # route registration and handlers
routing/ # custom router (exact URL matching, method enforcement)
server/ # alternate ListenAndServe wrapper (unused by main.go)
utils/
errors/ # JSON error types (400, 403, 404)
logger/ # leveled logging (INFO/WARN/ERROR)
Register in api/routes.go using a handler that returns an error:
apiRouter.RegisterRoute("GET", "/path", func(w http.ResponseWriter, r *http.Request) error {
return nil // or return errors.NewNotFoundError(...)
})Returned errors are automatically serialized to JSON with the correct HTTP status code.