- Go 99.7%
- Dockerfile 0.3%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| cmd | ||
| internal | ||
| migrations | ||
| postman | ||
| sqlboiler | ||
| .gitignore | ||
| .golangci.yml | ||
| app.env | ||
| CODE_OF_CONDUCT.md | ||
| docker-compose.yml | ||
| favicon.ico | ||
| go.mod | ||
| go.sum | ||
| LICENSE | ||
| logo.png | ||
| README.md | ||
| Taskfile.yml | ||
realworld-go codebase containing a real-world example (CRUD, auth, advanced patterns, etc.) that adheres to the RealWorld spec and API.
Demo RealWorld
This codebase was created to demonstrate a fully-fledged backend application built with Go, Chi, and SQLBoiler, including CRUD operations, authentication, routing, pagination, and more.
We've gone to great lengths to adhere to the Go community style guides & best practices.
For more information on how this works with other frontends/backends, head over to the RealWorld repo.
Develop
Task: build tool
This project uses Task as task runner and build tool. Checkout the installation instruction here:
https://taskfile.dev/installation/
Goose: database migration
goose is used as database migration tool. The migration SQL scripts are in the migrations folder. The source code of the migration tool is located here: cmd/migrate/main.go
To build the migration tool, run task build-goose. The migration reads the database connection configuration from the app.env file.
Migration related tasks:
| Task | Description |
|---|---|
db-migration-new-go |
Creates an empty Go migration file |
db-migration-new |
Creates an empty SQL migration file |
db-migration-reset |
Reverts all migrations. Results in an empty database |
db-migration-status |
Shows the current applied migration version |
db-migration-up |
Runs all migrations if not already applied |
SQLBoiler: database access
The project utilizes SQLBoiler as the database access layer. SQLBoiler depends on generated code that needs to be re-generated each time the database schema changes. SQLBoiler reads the information from the database and creates files in the folder internal/models. Database connection parameters are configured in the file sqlboiler/sqlboiler.toml. First apply the schema changes with goose and then run task db-codegen to generate the database code.
Getting started
- Install Task
- Start PostgreSQL with
docker compose up -d - Apply database migration
task db-migration-up - Start API with
task run - Run the realworld Postman collection
cd postman
npm install
npm start
