go-lmu-setup-api

module
v0.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2025 License: MIT

README

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

  1. Clone the repo
git clone https://gitlab.com/slax0rr/go-lmu-setup-api.git
cd go-lmu-setup-api
  1. Generate JWT keys (for auth)
make genkeys
  1. Install dev tools & generate code
make install      # installs mockery & wire
make mocks wire   # generates interface mocks and DI code
  1. Start dependencies (Postgres + Auth service via Docker Compose)
make docker_start
  1. (Optional) Populate sample data
make db_populate
  1. 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

make test
# or
go test -v ./...

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!

  1. Fork the repo
  2. Create a feature branch
  3. Submit a merge request

Please run make test before submitting.

License

MIT License – see LICENSE for details.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL