This is a simple notification service written in Go (Golang) that allows you to send notifications via email, HTML email, SMS, and push notifications. It provides an HTTP API endpoint for receiving notification requests and queues them for processing.
- Supports multiple notification channels: email, HTML email, SMS, and push notifications.
- Configurable retry mechanism for failed notifications.
- Asynchronous processing using a job queue.
To send a notification, make a POST request to the /notify
endpoint with the following JSON payload:
{
"channel": "email",
"to": "recipient@example.com",
"subject": "Test Email",
"body": "This is a test email.",
"retries": 3,
"delay": 5
}
Replace the "channel" value with the desired notification channel ("email", "html_email", "sms", or "push"), and fill in the "to", "subject", and "body" fields accordingly. You can also specify the number of "retries" and the "delay" in seconds between each retry.
The configuration of the notification service can be adjusted using environment variables. The following variables are supported:
- ENVIRONMENT: Set the environment mode (development or production).
- SMTP_HOST: SMTP: server host address.
- SMTP_PORT: SMTP: server port number.
- SMTP_USERNAME: SMTP username.
- SMTP_PASSWORD: SMTP password.
- SMS_API_KEY: API key for SMS service provider.
- PUSH_API_KEY: API key for push notification service provider.
- JOB_QUEUE_SIZE: Size of the job queue.
- JOB_WORKER_COUNT: Number of worker threads for processing jobs.
- SERVER_ADDRESS: Address and port on which the server should listen.
For SMS and push notifications, you need to implement the respective logic in the channels/SMS.go and channels/Push.go files. Replace the placeholder implementation with the actual logic for sending SMS and push notifications.
-
Clone the repository:
git clone https://github.com/AmirhoseinMasoumi/notification-service.git cd notification-service
-
Edit the .env file with your configuration settings.
-
Build and run the application:
go build -o notification-service main.go ./notification-service
Contributions are welcome! Please fork the repository and create a pull request. For major changes, open an issue to discuss what you would like to change.
- Fork the repository
- Create your 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.