Add REST API response pattern package with multi-format support and i18n#6
Draft
Add REST API response pattern package with multi-format support and i18n#6
Conversation
Co-authored-by: bos-hieu <9217908+bos-hieu@users.noreply.github.com>
Co-authored-by: bos-hieu <9217908+bos-hieu@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add README.md for flexible REST API response pattern
Add REST API response pattern package with multi-format support and i18n
Nov 8, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements a framework-agnostic REST API response pattern library supporting multiple standard formats (Envelope, Flat, Lean, HAL, Validation) with built-in internationalization for validation errors.
Package Structure
go-playground/validator/v10with EN/VI translationsUsage
Format Examples
Envelope (
?format=envelope):{"success": true, "data": {...}, "meta": {...}}Validation with Vietnamese (
?lang=vi):{ "error": { "code": "INVALID_INPUT", "errors": [ {"field": "Email", "message": "Email phải là giá trị email address"} ] } }Dependencies
Adds
go-playground/validator/v10ecosystem for validation and translation support.Testing
47 test cases covering all formats and i18n scenarios (87.5% coverage).
Original prompt
Updated Question:
Please write a complete README.md that describes the flexible REST API response pattern solution (Envelope, Flat, Lean, HAL, Validation, i18n) so I can give it to Copilot to implement across multiple Go frameworks like Gin and Fiber.
⸻
Answer:
Here’s your ready-to-use README.md file 👇
⸻
🌐 Go REST API Response Pattern — Flexible and Framework-Agnostic
A clean, consistent, and extensible Result/Response Pattern for REST APIs in Go.
Supports multiple formats (Envelope, Flat, Lean, HAL, Validation) and works across frameworks like Gin, Fiber, Echo, etc.
🚀 Features
✅ Consistent and reusable response structure
✅ Supports multiple response formats:
✅ Internationalization (i18n) with multi-language support (e.g., English, Vietnamese)
✅ Compatible with any HTTP framework (Gin, Fiber, Echo, Chi, net/http)
✅ Easy to extend with custom error codes or metadata
🧱 Folder Structure Example
response/
│── envelope.go # Envelope format
│── flat.go # Flat format
│── lean.go # Lean format
│── hal.go # HAL format
│── validation.go # Validation format
│── builder.go # Common writer and helpers
│── i18n.go # Validator + translations
📦 Install Dependencies