HTTP application demo based on the Yokai Go framework.
This demo provides a REST API example, with:
- a Yokai application container (with Air):
- with the HTTP server module
- with a fxdatabase module, to provide
database/sql
+ gomigrate - with a fxsqlc module, to provide sqlc
- a MySQL container for storage
- a Jaeger container for tracing
This demo is following the recommended project layout:
cmd/
: entry pointsconfigs/
: configuration filesdb/
migrations/
: SQL migrations files for gomigratequeries/
: SQL queries files for sqlc stubs generationsqlc/
: sqlc generated stubs
internal/
:handler/
: HTTP handlersmodule/
:fxdatabase
: database/sql + gomigrate modulefxsqlc
: sqlc module
bootstrap.go
: bootstrapregister.go
: dependencies registrationrouter.go
: routing registration
sqlc.yaml
: sqlc configuration
This template provides a Makefile:
make up # start the docker compose stack
make down # stop the docker compose stack
make logs # stream the docker compose stack logs
make fresh # refresh the docker compose stack
make sqlc # regenerate sqlc stubs
make migrate-create # create migration
make migrate-up # apply all migrations
make migrate-down # revert all migrations
make test # run tests
make lint # run linter
Start the application with:
make fresh
Then apply database migrations with:
make migrate-up
Once ready, the application will be available on:
- http://localhost:8080 for the application HTTP server
- http://localhost:8081 for the application core dashboard
- http://localhost:16686 for the Jaeger dashboard
Available endpoints on http://localhost:8080:
Route | Description |
---|---|
[GET] /owners |
List all owners |
[POST] /owners |
Create an owner |
[GET] /owners/:id |
Get an owner |
[DELETE] /gophers/:id |
Delete an owner |