Prerequisites
- Install Go:
Download and install Go from the official website: https://golang.org/dl/
- Install Docker:
Download and install Docker from the official website: https://www.docker.com/get-started
- Set up environment variables:
Create a
.envfile in the project root directory with the following content:SUPABASE_PROJECT_REF= SUPABASE_ANON_KEY= SUPABASE_SERVICE_ROLE_KEY= PORT=8080
Initialize the Go Project
Run the following commands to initialize the Go module and install dependencies:
go mod init nextinbox
go mod tidy
go get github.com/gorilla/mux github.com/joho/godotenv github.com/lengzuo/supa github.com/rs/cors golang.org/x/time/rate
Build and Run Locally
- Build the application:
go build -o main . - Run the application:
./main - Test the application:
Access http://localhost:8080/health in your browser or use a tool like
curl:curl http://localhost:8080/health
API Reference
/health
Check if the API is running.
/api/v1/send
Send an email using a template.
Request Body:
{
"user_key": "nib_user_example_key",
"service_id": "12345-service",
"template_id": "template-67890",
"recipients": [
{
"email_address": "user@example.com",
"name": "Alice"
}
],
"parameters": {
"customer_name": "Alice",
"incentive": "10% off",
"expiration_date": "2023-12-31"
}
}
Docker Instructions
- Build the Docker image:
docker build -t nextinbox . - Push the Docker image to Docker Hub:
docker login docker push your_dockerhub_username/nextinbox:latest - Run the Docker container locally:
docker run -p 8080:8080 nextinbox
Deploying on Koyeb Using Docker Image
- Log in to Koyeb:
Visit Koyeb's website and log in to your account.
- Create a New App:
In the Koyeb dashboard, click on Create App.
- Configure App Deployment:
Select Docker Hub as the deployment source. Enter your Docker image name, e.g.,
your_dockerhub_username/nextinbox:latest. - Deploy the App:
Click on Deploy to start the deployment process.
- Access the Application:
Once deployed, Koyeb will provide you with a URL to access your application. Use this URL to test the application.
- Test Health Endpoint:
Verify that the application is running by accessing the
/healthendpoint in your browser or usingcurl:curl <your-koyeb-app-url>/health