Exemplary real world application built with Golang + Gin
See the code
Golang/Gin codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld spec and API.
This codebase was created to demonstrate a fully fledged fullstack application built with Golang/Gin including CRUD operations, authentication, routing, pagination, and more.
This project has been modernized with the following updates:
GET /profiles/:username now supports optional authentication (anonymous access allowed)POST /users/login returns 401 Unauthorized on failure (previously 403)GET /articles/feed registered as dedicated authenticated routeDELETE /articles/:slug and DELETE /articles/:slug/comments/:id return empty response bodyThe project maintains high test coverage across all core packages:
| Package | Coverage |
|---|---|
articles | 93.4% |
users | 99.5% |
common | 85.7% |
| Total | 90.0% |
To generate a coverage report locally, run:
go test -coverprofile=coverage.out ./...
go tool cover -func=coverage.out
| Package | Version | Release Date | Known Issues |
|---|---|---|---|
| gin-gonic/gin | v1.10.0 | 2024-05 | None; v1.11 has experimental HTTP/3 support |
| gorm.io/gorm | v1.25.12 | 2024-08 | None; v1.30+ has breaking changes |
| golang-jwt/jwt/v5 | v5.2.1 | 2024-06 | None; v5.3 only bumps Go version requirement |
| go-playground/validator/v10 | v10.24.0 | 2024-12 | None; v10.30+ requires Go 1.24 |
| golang.org/x/crypto | v0.32.0 | 2025-01 | None; keep updated for security fixes |
| gorm.io/driver/sqlite | v1.5.7 | 2024-09 | None; requires cgo; use glebarez/sqlite for pure Go |
| gosimple/slug | v1.15.0 | 2024-12 | None |
| stretchr/testify | v1.10.0 | 2024-10 | None; v2 still in development |
.
├── gorm.db
├── hello.go
├── common
│ ├── utils.go //small tools function
│ └── database.go //DB connect manager
├── users
| ├── models.go //data models define & DB operation
| ├── serializers.go //response computing & format
| ├── routers.go //business logic & router binding
| ├── middlewares.go //put the before & after logic of handle request
| └── validators.go //form/json checker
├── ...
...
Make sure you have Go 1.21 or higher installed.
https://golang.org/doc/install
Environment variables can be set directly in your shell or via a .env file (requires a tool like source or direnv).
Available environment variables:
PORT=8080 # Server port (default: 8080)
GIN_MODE=debug # Gin mode: debug or release
DB_PATH=./data/gorm.db # SQLite database path (default: ./data/gorm.db)
TEST_DB_PATH=./data/test.db # Optional: SQLite database path used for tests
Example usage:
# Option 1: Set environment variables directly
export PORT=3000
export DB_PATH=./data/myapp.db
go run hello.go
# Option 2: Inline with command
PORT=3000 go run hello.go
See .env.example for a complete template.
From the project root, run:
go build ./...
go test ./...
go mod tidy
# Using default port 8080
go run hello.go
# Using custom port
PORT=3000 go run hello.go
From the project root, run:
go test ./...
or
go test ./... -cover
or
go test -v ./... -cover
depending on whether you want to see test coverage and how verbose the output you want.
Current test coverage (2026):
Run coverage report:
go test -coverprofile=coverage.out ./...
go tool cover -func=coverage.out
285 followers · starred Aug 2019
158 followers · starred May 2018
249 followers · starred Jul 2021
33 followers · starred Nov 2022
Exemplary real world application built with Golang + Gin
See the code
Golang/Gin codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld spec and API.
This codebase was created to demonstrate a fully fledged fullstack application built with Golang/Gin including CRUD operations, authentication, routing, pagination, and more.
This project has been modernized with the following updates:
GET /profiles/:username now supports optional authentication (anonymous access allowed)POST /users/login returns 401 Unauthorized on failure (previously 403)GET /articles/feed registered as dedicated authenticated routeDELETE /articles/:slug and DELETE /articles/:slug/comments/:id return empty response bodyThe project maintains high test coverage across all core packages:
| Package | Coverage |
|---|---|
articles | 93.4% |
users | 99.5% |
common | 85.7% |
| Total | 90.0% |
To generate a coverage report locally, run:
go test -coverprofile=coverage.out ./...
go tool cover -func=coverage.out
| Package | Version | Release Date | Known Issues |
|---|---|---|---|
| gin-gonic/gin | v1.10.0 | 2024-05 | None; v1.11 has experimental HTTP/3 support |
| gorm.io/gorm | v1.25.12 | 2024-08 | None; v1.30+ has breaking changes |
| golang-jwt/jwt/v5 | v5.2.1 | 2024-06 | None; v5.3 only bumps Go version requirement |
| go-playground/validator/v10 | v10.24.0 | 2024-12 | None; v10.30+ requires Go 1.24 |
| golang.org/x/crypto | v0.32.0 | 2025-01 | None; keep updated for security fixes |
| gorm.io/driver/sqlite | v1.5.7 | 2024-09 | None; requires cgo; use glebarez/sqlite for pure Go |
| gosimple/slug | v1.15.0 | 2024-12 | None |
| stretchr/testify | v1.10.0 | 2024-10 | None; v2 still in development |
.
├── gorm.db
├── hello.go
├── common
│ ├── utils.go //small tools function
│ └── database.go //DB connect manager
├── users
| ├── models.go //data models define & DB operation
| ├── serializers.go //response computing & format
| ├── routers.go //business logic & router binding
| ├── middlewares.go //put the before & after logic of handle request
| └── validators.go //form/json checker
├── ...
...
Make sure you have Go 1.21 or higher installed.
https://golang.org/doc/install
Environment variables can be set directly in your shell or via a .env file (requires a tool like source or direnv).
Available environment variables:
PORT=8080 # Server port (default: 8080)
GIN_MODE=debug # Gin mode: debug or release
DB_PATH=./data/gorm.db # SQLite database path (default: ./data/gorm.db)
TEST_DB_PATH=./data/test.db # Optional: SQLite database path used for tests
Example usage:
# Option 1: Set environment variables directly
export PORT=3000
export DB_PATH=./data/myapp.db
go run hello.go
# Option 2: Inline with command
PORT=3000 go run hello.go
See .env.example for a complete template.
From the project root, run:
go build ./...
go test ./...
go mod tidy
# Using default port 8080
go run hello.go
# Using custom port
PORT=3000 go run hello.go
From the project root, run:
go test ./...
or
go test ./... -cover
or
go test -v ./... -cover
depending on whether you want to see test coverage and how verbose the output you want.
Current test coverage (2026):
Run coverage report:
go test -coverprofile=coverage.out ./...
go tool cover -func=coverage.out
285 followers · starred Aug 2019
158 followers · starred May 2018
249 followers · starred Jul 2021
33 followers · starred Nov 2022