Skip to content

Gin starting point with sqlc, htmx, auth and bits. Just playing around.

Notifications You must be signed in to change notification settings

AccentDesign/gin-boilerplate

 
 

Repository files navigation

Gin Boilerplate

  • Manage the database schema and apply migrations in pkg/storage/db/migrations.
  • Manage the queries in pkg/storage/db/sqlc.
  • Generated query directory pkg/storage/db/dbx.
  • Manage the templates in pkg/ui.

Go Tasks

install go task package to run commands defined in Taskfile.yml:

go install github.com/go-task/task/v3/cmd/task@latest

then install all dev tooling:

task setup:tooling

list all tasks:

task --list-all

Config

For configuration see the config.toml passed in as the --config flag to app.

Tip

Generate new session auth keys ask ChatGPT

"Could you generate random hex keys of 32 bytes and 16 bytes for me?"

create your dev config:

task setup:config

SQL

make sure to use the correct db dsn in sqlc.yml and that the db is fully migrated.

generate go code from sql:

task gen:sqlc

Migrations

new:

task migrate:add SEQ="migration_name"

up:

task migrate:up

down:

task migrate:down

Templates

Generate template code with templ.guide

task gen:templ

Usage

use air to generate the templates and run the server:

air

list app commands:

go run . help

run the server:

go run . server --config config.dev.toml

create a user:

go run . createuser --config config.dev.toml \
--email admin@example.com \
--password password \
--firstname Admin \
--lastname User

Tailwind

For simplicity we are using the standalone cli.

download the cli to the tmp folder (created once air is run):

curl -sLO https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-macos-arm64
chmod +x tailwindcss-macos-arm64
mv tailwindcss-macos-arm64 tmp/tailwindcss

build and watch:

task gen:tailwind

Docker

This can be used to build the app as a binary and run it in a container.

build:

docker build --build-arg EXPOSE_PORT=80 -t gin-boilerplate:latest .

run:

docker run \
--rm \
--name gin-boilerplate \
--publish "80:80" \
--env "DATABASE_HOST=host.docker.internal" \
--env "SERVER_MODE=release" \
--env "SERVER_PORT=80" \
gin-boilerplate:latest \
server --config config.toml

if you need it create a postgres container for the database:

docker run \
--detach \
--name "gin-postgres" \
--mount type=tmpfs,destination=/var/lib/postgresql/data \
--publish "5432:5432" \
--env POSTGRES_USER=postgres \
--env POSTGRES_PASSWORD=password \
--env POSTGRES_DB=gin-boilerplate \
postgres:latest

Links

About

Gin starting point with sqlc, htmx, auth and bits. Just playing around.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 73.4%
  • templ 11.4%
  • CSS 8.9%
  • PLpgSQL 3.5%
  • JavaScript 1.8%
  • Dockerfile 1.0%