- 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
.
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
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
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
new:
task migrate:add SEQ="migration_name"
up:
task migrate:up
down:
task migrate:down
Generate template code with templ.guide
task gen:templ
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
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
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