From 8ddfe7a6266289f7d31a034cc1317b8ef174c0c0 Mon Sep 17 00:00:00 2001 From: Sergey Chubaryan Date: Fri, 7 Feb 2025 13:07:19 +0300 Subject: [PATCH] validate email fields in request --- cmd/backend/server/handlers/user_create_handler.go | 6 +++--- cmd/backend/server/handlers/user_login_handler.go | 2 +- internal/http_server/wrapper.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/backend/server/handlers/user_create_handler.go b/cmd/backend/server/handlers/user_create_handler.go index 70d4a30..392bbdb 100644 --- a/cmd/backend/server/handlers/user_create_handler.go +++ b/cmd/backend/server/handlers/user_create_handler.go @@ -10,9 +10,9 @@ import ( ) type createUserInput struct { - Email string `json:"email"` - Password string `json:"password"` - Name string `json:"name"` + Email string `json:"email" validate:"required,email"` + Password string `json:"password" validate:"required"` + Name string `json:"name" validate:"required"` } type createUserOutput struct { diff --git a/cmd/backend/server/handlers/user_login_handler.go b/cmd/backend/server/handlers/user_login_handler.go index 72aa789..90193dd 100644 --- a/cmd/backend/server/handlers/user_login_handler.go +++ b/cmd/backend/server/handlers/user_login_handler.go @@ -10,7 +10,7 @@ import ( ) type loginUserInput struct { - Login string `json:"email"` + Login string `json:"email" validate:"required,email"` Password string `json:"password"` } diff --git a/internal/http_server/wrapper.go b/internal/http_server/wrapper.go index 0f866ee..f96d6a4 100644 --- a/internal/http_server/wrapper.go +++ b/internal/http_server/wrapper.go @@ -8,7 +8,7 @@ import ( "github.com/gin-gonic/gin" ) -type Handler[Input, Output any] func(ctx context.Context, input Input) (Output, error) +type Handler[Input, Output interface{}] func(ctx context.Context, input Input) (Output, error) type ResponseOk struct { Status string `json:"status"`