Skip to main content

Email Verification Service with Fiber

Github StackBlitz

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

MethodURLDescription
POST/verify/send/:emailSend verification code
POST/verify/check/:email/:codeVerify the received code

Example Usage

  1. Send verification code:
curl -X POST http://localhost:3000/verify/send/user@example.com
  1. 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

  1. Configure SMTP settings in config/config.go
  2. Run the application:
go run main.go

Dependencies