This project is a Go application for managing email campaigns. It includes several components such as campaign services, email sending infrastructure, and route handling.
cmd/api/main.go
: The main entry point of the application.internal/domain/campaign
: Contains the business logic for campaigns.internal/infrastructure/mail
: Handles email sending functionalities.internal/infrastructure/repository
: Manages database interactions.internal/routes
: Defines HTTP routes and handlers.
- Go (1.18 or later)
- Docker (optional, for running a local database)
- Make sure to have a
.env
file at the root of your project directory with the necessary environment variables.
-
Clone the repository:
git clone https://github.com/thiagoadsix/email-go.git cd email-campaign-service
-
Install dependencies:
go mod download
-
Set up your environment variables in a
.env
file:touch .env
Add the following content to the
.env
file:DATA_BASE_URL="host=localhost user=emailn_dev password=12345678 port=5432 sslmode=disable" KEYCLOAK_URL="http://localhost:8080/realms/emailn_realm" GOMAIL_SMTP="smtp.gmail.com" GOMAIL_USER="your_email_test@gmail.com" GOMAIL_PASS="your_app_password_google_account"
-
Start the application:
go run cmd/api/main.go
-
The application will be running on
http://localhost:8080
.
POST /campaigns
: Create a new campaign.GET /campaigns
: Retrieve a list of campaigns.GET /campaigns/{id}
: Retrieve a specific campaign by ID.PUT /campaigns/{id}
: Update a specific campaign by ID.DELETE /campaigns/{id}
: Delete a specific campaign by ID.POST /campaigns/{id}/send
: Send a campaign.
- Make sure your database is up and running.
- Use an API client like Postman to interact with the endpoints.
We are using Keycloak for authentication and authorization. Keycloak is an open-source Identity and Access Management solution aimed at modern applications and services.
github.com/coreos/go-oidc/v3 v3.10.0
: OpenID Connect (OIDC) client implementation.github.com/go-chi/chi/v5 v5.0.14
: Lightweight, idiomatic, and composable router for building Go HTTP services.github.com/go-chi/render v1.0.3
: Rendering utilities for HTTP responses.github.com/go-playground/validator/v10 v10.22.0
: Go (golang) package for data validation.github.com/golang-jwt/jwt/v5 v5.2.1
: A Go implementation of JSON Web Tokens (JWT).github.com/jaswdr/faker v1.19.1
: Faker is a library for generating fake data.github.com/joho/godotenv v1.5.1
: Go port of Ruby's dotenv library (loads environment variables from.env
).github.com/rs/xid v1.5.0
: Xid is a globally unique id generator.github.com/stretchr/testify v1.9.0
: A toolkit with common assertions and mocks that plays nicely with the standard library.gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
: A simple and efficient package to send emails.gorm.io/driver/postgres v1.5.9
: GORM PostgreSQL driver.gorm.io/gorm v1.25.10
: The fantastic ORM library for Golang.
- Fork the repository.
- Create a new feature branch (
git checkout -b feature/YourFeature
). - Commit your changes (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature/YourFeature
). - Open a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.