realworld-go codebase containing a real-world example (CRUD, auth, advanced patterns, etc.) that adheres to the RealWorld spec and API.
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.
This project uses Task as task runner and build tool. Checkout the installation instruction here:
https://taskfile.dev/installation/
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 |
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.
- 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