This is a Go project that provides a service for managing user subscriptions to events.
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 and the users-service running.
- Go
- PostgreSQL
- Docker (optional)
- Users Service (gRPC)
-
Clone the repository:
git clone gitlab.com/velo-company/services/events-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.GEMINI_API_KEY: The API key for the Gemini service.USER_SERVICE_GRPC_ADDRESS: The address for the User Service gRPC server.
-
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 events-service . - Run the Docker container:
docker run --env-file .env -p 8080:8080 events-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.ai: Contains adapters for AI services like Gemini.database: Contains the adapters for modifying PostgreSQL Data.grpc: Contains the adapters for calling procedures in other APIs.http: Contains the REST controllers (handlers).
core: Contains the core domain logic.entities: Contains the domain models.errors: Contains custom error types.ports: Contains the interfaces for the repositories and services.services: Contains the application services.
proto: Contains the protobuf files for the gRPC services.
All endpoints are prefixed with /api/events/v1 and require JWT authentication.
POST /subscribe/:id: Subscribes the authenticated user to the event with the specified ID.POST /cancel-subscription/:id: Cancels the authenticated user's subscription to the event with the specified ID.POST /confirm-subscription/:id: Confirms the user's subscription to the event with a confirmation code.GET /confirmation-code/:id: Retrieves the confirmation code for a user's subscription to an event.
To create a new migration, you can use a tool like migrate:
migrate create -ext sql -dir db/migrations -seq create_my_migrationThis will create new up and down migration files 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.protoTo generate the swagger documentation, you can use the following command:
swag init -g cmd/api/main.go -o docs/This will generate the docs/ folder with the swagger documentation.
The project uses the following primary dependencies:
- github.com/gin-gonic/gin
- github.com/golang-jwt/jwt/v5
- github.com/joho/godotenv
- github.com/lib/pq
- google.golang.org/grpc
- google.golang.org/protobuf
- github.com/google/generative-ai-go
Contributions are welcome! Please open an issue or submit a pull request.