- 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
.
for migrations:
go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
for sqlc:
go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
for template rendering:
go install github.com/a-h/templ/cmd/templ@latest
for air reloading:
go install github.com/air-verse/air@latest
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?"
make sure to use the correct db dsn in sqlc.yml
and that the db is fully migrated.
sqlc generate
new, requires golang-migrate
cli to be installed:
migrate create -ext sql -dir pkg/storage/db/migrations \
-seq <do_something>
up:
go run . migrate --config config.dev.toml up
down:
go run . migrate --config config.dev.toml down
Generate template code with templ.guide
templ generate
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
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
create the container:
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
Just a basic test with wrk, no real load testing was done. Logging was disabled for the test.
logged in with real user and session cookie, postgres db on localhost:
wrk -c 400 -t 10 -d 30s -H "Cookie: session=..." http://localhost
Running 30s test @ http://localhost
10 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 20.20ms 2.00ms 71.96ms 88.29%
Req/Sec 1.99k 144.93 2.24k 85.63%
593341 requests in 30.02s, 796.16MB read
Socket errors: connect 0, read 402, write 0, timeout 0
Requests/sec: 19763.59
Transfer/sec: 26.52MB
not logged in:
wrk -c 400 -t 10 -d 30s http://localhost/auth/login
Running 30s test @ http://localhost/auth/login
10 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 5.40ms 3.32ms 86.58ms 84.56%
Req/Sec 7.68k 645.82 16.49k 89.63%
2294661 requests in 30.04s, 4.52GB read
Socket errors: connect 0, read 406, write 0, timeout 0
Requests/sec: 76392.72
Transfer/sec: 154.23MB