go-lmu-setup-api
go-lmu-setup-api is a Go-based HTTP service for managing car setups and calculating race strategies (pit stops, stints, fuel and tire management) via a RESTful API.
Features
- CRUD APIs for Cars, Tracks, Track Layouts and Setups
- Race strategy calculations (optimal pit-stop timing, stint planning)
- PostgreSQL persistence with automatic migrations
- JWT-based authentication integration
- In-memory caching for improved performance
- Health checks, structured logging (Zerolog) and error handling
Prerequisites
Getting Started
- Clone the repo
git clone https://gitlab.com/slax0rr/go-lmu-setup-api.git
cd go-lmu-setup-api
- Generate JWT keys (for auth)
make genkeys
- Install dev tools & generate code
make install # installs mockery & wire
make mocks wire # generates interface mocks and DI code
- Start dependencies (Postgres + Auth service via Docker Compose)
make docker_start
- (Optional) Populate sample data
make db_populate
- Run the API server
make run
This will build the binary, run DB migrations, and start listening on port 8000.
Alternatively, you can run directly with Go (passing env vars):
go run cmd/go-lmu-setup-api/main.go \
--SERVER_PORT=8000 \
--DATABASE_DSN=postgres://lmu_setups_user:devpass@localhost:5433/lmu_setups \
--USER_TOKEN_ENCODED_KEY=<base64-secret> \
--USERS_API_INTERNAL_BASE_URL=http://localhost:8008/api/v1
Configuration
Configure the service via environment variables (defaults in parentheses):
- SERVICE_NAME (go-lmu-setup-api)
- SERVER_PORT (8000)
- LOG_LEVEL (debug)
- DATABASE_DSN (built from DATABASE_USER, DATABASE_PASSWORD, DATABASE_HOST, DATABASE_NAME, DATABASE_PORT)
- DATABASE_USER (lmu_setups_user)
- DATABASE_PASSWORD (devpass)
- DATABASE_HOST (localhost)
- DATABASE_NAME (lmu_setups)
- DATABASE_PORT (5433)
- DB_MIGRATIONS_LOCATION (./internal/app/go-lmu-setup-api/infra/database/migrations)
- USER_TOKEN_ENCODED_KEY (base64-encoded secret)
- USERS_API_INTERNAL_BASE_URL (http://localhost:8008/api/v1)
Running Tests
Majority of tests are integration tests and the server is printing a lot of debug logs while running the tests, making the tracing in the huge output difficult. Therefor, to run the tests and get only a high level of failure notifications run:
make test
In order to drill down into the specific functions you can provide the function regex as you would for the go test -run flag you can provide it in the TEST_FUNC variable, which will run only the matching test functions and print all of the output for them.
make TEST_FUNC="^TestSomething_*" test
To run the verbose tests and get all of the output:
make TEST_VERBOSE=1 test
# or
go run -v -count1 ./...
Docker Build & Run
make build-image
docker run --rm -p 8000:8000 \
-e DATABASE_DSN=postgres://... \
-e USER_TOKEN_ENCODED_KEY=<secret> \
-e USERS_API_INTERNAL_BASE_URL=http://auth:8000/api/v1 \
go-lmu-setup-api:latest
API Endpoints
API Endpoints are documented under docs/swagger/openapi3.json. Any updates to the API must be documented there by either updating the JSON file manually or by generating swagger docs, by annotating relevant routes in the source code and run:
make swagger
The make target will generate OpenAPI v3 spec under ./swagger/ from where you need to copy relevant documentation to ./docs/swagger/openapi3.json file. Before committing documentation changes, remove the annotations in the source code.
Installing swagger
To install necessary tools for swagger documentation generation you will need sudo and run:
make install-swagger
Project Structure
cmd/ # application entrypoint
internal/app/... # core service (domain, use-cases, infra)
pkg/bootstrapify # bootstrapping & components framework
docker/ # Docker Compose + Traefik configs
docs/adr # architecture decision records
docs/swagger # API endpoint documentation
Contributing
Contributions are very welcome!
- Fork the repo
- Create a feature branch
- Submit a merge request
Please run make test before submitting.
License
MIT License – see LICENSE for details.