Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

101 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Events Service

This is a Go project that provides a service for managing user subscriptions to events.

Go PostgreSQL Sentry gRPC Datadog GCP RabbitMQ

Getting Started

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.

Prerequisites

  • Go
  • PostgreSQL
  • Docker (optional)
  • Users Service (gRPC)

Installation

  1. Clone the repository:

    git clone gitlab.com/velo-company/services/events-service
  2. Install the dependencies:

    go mod tidy
  3. 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.
  4. 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
  5. Run the server:

    go run cmd/api/main.go

Docker

To build and run the project using Docker, you can use the following commands:

  1. Build the Docker image:
    docker build -t events-service .
  2. Run the Docker container:
    docker run --env-file .env -p 8080:8080 events-service

Folder Structure

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.

API Endpoints

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.

Development

Creating Migrations

To create a new migration, you can use a tool like migrate:

migrate create -ext sql -dir db/migrations -seq create_my_migration

This will create new up and down migration files in the db/migrations folder.

Running Migrations

To run the migrations, you can use the following command:

migrate -path db/migrations -database "postgres://user:password@host:port/dbname?sslmode=disable" up

Make sure to replace the connection string with your own.

Generating Protobuf

To generate the .pb.go file from the .proto file, you can use the following command:

protoc --go_out=. --go-grpc_out=. proto/user.proto

Swagger Documentation

To 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.

Dependencies

The project uses the following primary dependencies:

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

About

No description or website provided.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages