Skip to content

Commit 48baaf5

Browse files
committed
Refactor comments and import order in custom validation error example
1 parent ea3a227 commit 48baaf5

File tree

1 file changed

+10
-10
lines changed
  • _examples/custom_validation_error

1 file changed

+10
-10
lines changed

_examples/custom_validation_error/main.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@ package main
33
import (
44
"log"
55

6-
fiberoapi "github.com/labbs/fiber-oapi"
76
"github.com/gofiber/fiber/v2"
7+
fiberoapi "github.com/labbs/fiber-oapi"
88
)
99

10-
// CustomErrorResponse représente votre structure d'erreur personnalisée
10+
// CustomErrorResponse is the structure for custom validation error responses
1111
type CustomErrorResponse struct {
1212
Success bool `json:"success"`
1313
Message string `json:"message"`
1414
Code string `json:"code"`
1515
}
1616

17-
// CreateUserInput représente l'entrée pour créer un utilisateur
17+
// CreateUserInput is the input structure for creating a user
1818
type CreateUserInput struct {
1919
Name string `json:"name" validate:"required,min=3"`
2020
Email string `json:"email" validate:"required,email"`
2121
Age int `json:"age" validate:"required,min=18,max=100"`
2222
}
2323

24-
// CreateUserOutput représente la sortie
24+
// CreateUserOutput is the output structure for creating a user
2525
type CreateUserOutput struct {
2626
ID int `json:"id"`
2727
Name string `json:"name"`
@@ -33,14 +33,14 @@ type CreateUserOutput struct {
3333
func main() {
3434
app := fiber.New()
3535

36-
// Configurer fiber-oapi avec un gestionnaire d'erreur de validation personnalisé
36+
// Configure fiber-oapi with a custom validation error handler
3737
oapi := fiberoapi.New(app, fiberoapi.Config{
3838
EnableValidation: true,
3939
EnableOpenAPIDocs: true,
40-
// Définir votre handler personnalisé pour les erreurs de validation
40+
// Define your custom handler for validation errors
4141
ValidationErrorHandler: func(c *fiber.Ctx, err error) error {
42-
// Vous pouvez parser l'erreur de validation pour extraire plus de détails
43-
// ou simplement retourner votre structure personnalisée
42+
// You can parse the validation error to extract more details
43+
// or simply return your custom structure
4444
return c.Status(fiber.StatusBadRequest).JSON(CustomErrorResponse{
4545
Success: false,
4646
Message: err.Error(),
@@ -49,12 +49,12 @@ func main() {
4949
},
5050
})
5151

52-
// Définir votre endpoint
52+
// Define your endpoint
5353
fiberoapi.Post[CreateUserInput, CreateUserOutput, struct{}](
5454
oapi,
5555
"/users",
5656
func(c *fiber.Ctx, input CreateUserInput) (CreateUserOutput, struct{}) {
57-
// Logique de création d'utilisateur
57+
// User creation logic goes here
5858
return CreateUserOutput{
5959
ID: 1,
6060
Name: input.Name,

0 commit comments

Comments
 (0)