This is a Go project that provides a service for managing tracks and routes.
To get started with this project, you'll need to have Go installed on your machine. You'll also need to have a running instance of PostgreSQL.
- Go
- PostgreSQL
- Docker (optional)
-
Clone the repository:
git clone https://github.com/velo-project/routes-service
-
Install the dependencies:
go mod tidy
-
Set up the environment variables:
cp .env.example .env
The following environment variables are used:
POSTGRES_CONNECTION_STRING: The connection string for the PostgreSQL database.RSA_PUBLIC_KEY: The path to the RSA public key for verifying JWT tokens.
-
Run the database migrations:
# Assuming makefile exists or using a migration tool migrate -path db/migrations -database "postgres://user:password@host:port/dbname?sslmode=disable" up
-
Run the server:
go run cmd/api/main.go
To build and run the project using Docker, you can use the following commands:
- Build the Docker image:
docker build -t routes-service . - Run the Docker container:
docker run --env-file .env -p 8080:8080 routes-service
The project is organized into the following folders:
cmd/api: Contains the main application entry point.db/migrations: Contains the database migrations.internal: Contains the core application logic.adapters: Contains the adapters for connecting to external services.database: Contains the adapters for modifying PostgreSQL Datagrpc: Contains the adapters for call procedures in other APIshttp: Contains the rest controllers
core: Contains the core domain logic.domain: Contains the domain models.ports: Contains the interfaces for the repositories and services.services: Contains the application services.
plan: Contains the project plan.proto: Contains the protobuf files for the gRPC services.
The following API endpoints are available:
POST /tracks: Creates a new track.GET /tracks: Finds all routes for a given user.DELETE /tracks/:trackId: Deletes a track.
To create a new migration, you can use the following command:
migrate create -ext sql -dir db/migrations -seq create_my_migrationThis will create a new migration file in the db/migrations folder.
To run the migrations, you can use the following command:
migrate -path db/migrations -database "postgres://user:password@host:port/dbname?sslmode=disable" upMake sure to replace the connection string with your own.
To generate the .pb.go file from the .proto file, you can use the following command:
protoc --go_out=. --go-grpc_out=. proto/user_service.protoThe project uses the following dependencies:
- gin-gonic/gin
- golang-jwt/jwt/v5
- google.golang.org/grpc
- google.golang.org/protobuf
- lib/pq
- joho/godotenv
Contributions are welcome! Please open an issue or submit a pull request.