Overview

In our Go architecture, we use go-playground/validator for data validation, which is similar to Zod in TypeScript. Both provide declarative, type-safe validation with excellent error messages.

📊 Comparison: Zod vs Go Validator


🎯 How It Works in Our Architecture

1. Define Request DTOs with Validation Tags

2. Validation Flow in HTTP Handler


🏗️ Architecture Layers

Data validation flow Data validation flow

📝 Common Validation Tags

Basic Validations

Advanced Validations


🎨 Custom Validation

1. Register Custom Validator

2. Use Custom Validator


🚨 Error Handling

Current Implementation

Error Response:

🔄 Comparison with Your TypeScript Code

TypeScript (Hono + Zod)

Go (Echo + Validator)


🎯 Best Practices

1. Separate DTOs from Domain Models

2. Layer-Specific Validation

3. Validation Groups (Optional)


📚 Available Validation Tags

Full list: https://pkg.go.dev/github.com/go-playground/validator/v10