A simple automatic message sending system built with Go.
This implementation is kept in a single file for simplicity and easy demonstration. In a production environment, I would structure it with:
- Separate packages (handlers, services, models)
- Database layer (PostgreSQL/MySQL)
- Redis caching for messageId storage
- Proper logging and error handling
- Configuration management
- Unit tests
I also put the environment variables to the .env file for you to test the service without having to set the environment variables manually. I removed the auth key for security reasons and put a placeholder.
# Clone and run
git clone https://github.com/yusuf-eren/lets-go-case
cd lets-go-case
go mod tidy
go run main.goSet environment variables:
export WEBHOOK_URL="https://webhook.site/02d3e3cd-8388-43e8-8687-586291bb6127"
export INS_AUTH_KEY="auth-key"
export BATCH_SIZE=2
export SEND_INTERVAL_MIN=2
export MESSAGE_CHAR_LIMIT=500
export PORT=8080GET /start- Start message sendingGET /stop- Stop message sendingGET /sent- Get all messages with status
- Sends all unsent messages immediately on startup
- Then sends 2 messages every 2 minutes
- Messages are marked as sent to prevent duplicates