/realworld-go

realworld backend implementation with Go

Primary LanguageGoMIT LicenseMIT

RealWorld Example App with Go, Chi and SQLBoiler

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.

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

  1. Install Task
  2. Start PostgreSQL with docker compose up -d
  3. Apply database migration task db-migration-up
  4. Start API with task run
  5. Run the realworld Postman collection
 cd postman   
 npm install   
 npm start