Skip to content

A template to scaffold a fullstack go web application

License

Notifications You must be signed in to change notification settings

ferdiebergado/go-fullstack-boilerplate

Repository files navigation

go-fullstack-boilerplate

Github Actions Github Actions Go Report Card

A template to scaffold a fullstack go web application.

Features

  • Standard Go Project Layout
  • Postgresql database using database/sql with pgx driver
  • Router based on net/http ServeMux
  • HTML templating using html/template
  • Typescript support out-of-the-box
  • Toolkit that makes common tasks easier
  • Database migrations
  • Hot reloading during development
  • nginx as web server and reverse proxy configured for high-performance
  • Docker deployment

Requirements

  • Go version 1.22 or higher
  • Docker

Getting Started

Step 1

Rename .env.example to .env.

mv .env.example .env

Step 2

Deploy the application.

make dev

Step 3

Browse the application at localhost:8080.

Migrations

Create Migrations

Run the migration target with the name of the migration as argument.

make migration create_users_table

Run Migrations

make migrate

Rollback Migrations

make rollback

Recover from a Failed Migration

When a migration fails, fix the error and force the version of the failed migration. Then run the migration again.

make force 1
make migrate

Bundling Assets

Bundle for development

make bundle

Watch mode for css files

make watch-css

Watch mode for typescript/javascript files

make watch-ts

Bundle for production

make bundle-prod

Tests

Run unit tests.

make test

Run integration tests.

make integration

Other Tasks

Interact with the database using psql

make psql

Restart a service

Provide a service as argument to the restart target.

make restart proxy

Stop all the running containers

make stop

Help

View the usage information by running make.

make

TODOs

  • Health endpoint
  • Login with email and password
  • Email verification
  • Secure Cookie Session Management
  • Login with Google (OAuth2)
  • Authorization
  • Audit logs
  • Database query caching
  • Environment Page (go version, drivers, env, os kernel, etc.)
  • Cache busting for assets

Linting

This project comes with a golangci-lint config file. Just install golangci-lint and enable it as the default linter on your editor of choice.

License

This project is distributed under the MIT License. See LICENSE for more details.

Tech Stack

Go TypeScript Postgres Nginx Docker