Email Verification Service with Fiber
A clean architecture based email verification service that generates and validates verification codes.
Features
- Clean Architecture implementation
- In-memory verification code storage
- SMTP email service integration
- Code generation and hashing
- Configurable code expiration
- Thread-safe operations
Project Structure
email-verification/
├── api/
│ └── handlers/ # HTTP handlers
├── application/ # Application business logic
├── domain/ # Domain models and interfaces
├── infrastructure/ # External implementations
│ ├── code/ # Code generation
│ ├── email/ # SMTP service
│ └── repository/ # Data storage
└── config/ # Configuration
Configuration
The application is configured via environment variables. Copy .env.example to .env and fill in your SMTP credentials:
cp .env.example .env
| Variable | Required | Default | Description |
|---|---|---|---|
SMTP_HOST | No | smtp.gmail.com | SMTP server hostname |
SMTP_PORT | No | 587 | SMTP server port |
SMTP_USER | Yes | — | SMTP username / email address |
SMTP_PASS | Yes | — | SMTP password or app-password |
The application exits with a fatal error on startup if SMTP_USER or SMTP_PASS are not set.
API Endpoints
| Method | URL | Description |
|---|---|---|
| POST | /verify/send/:email | Send verification code |
| POST | /verify/check/:email/:code | Verify the received code |
Example Usage
- Send verification code:
curl -X POST http://localhost:3000/verify/send/[email protected]
- Verify code:
curl -X POST http://localhost:3000/verify/check/[email protected]/123456
Response Examples
Success:
{
"message": "Code verified successfully"
}
Error:
{
"error": "invalid code"
}
How to Run
- Copy
.env.exampleto.envand set your SMTP credentials. - Export the environment variables and run the application:
export $(cat .env | xargs)
go run main.go
Dependencies
- Fiber v3
- Go 1.23+