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
Update config/config.go
with your SMTP settings:
func GetConfig() *Config {
return &Config{
SMTPHost: "smtp.gmail.com",
SMTPPort: 587,
SMTPUser: "your-email@gmail.com",
SMTPPassword: "your-app-password",
CodeExpiration: time.Minute * 1,
}
}
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/user@example.com
- Verify code:
curl -X POST http://localhost:3000/verify/check/user@example.com/123456
Response Examples
Success:
{
"message": "Code verified successfully"
}
Error:
{
"error": "invalid code"
}
How to Run
- Configure SMTP settings in
config/config.go
- Run the application:
go run main.go
Dependencies
- Fiber v2
- Go 1.21+