use embedded validation

This commit is contained in:
celogeek 2022-05-07 19:44:02 +02:00
parent 9b2a795e5c
commit c453422cac
Signed by: celogeek
GPG Key ID: E6B7BDCFC446233A

View File

@ -8,7 +8,6 @@ import (
"time" "time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gopkg.in/validator.v2"
"gorm.io/gorm" "gorm.io/gorm"
) )
@ -52,8 +51,8 @@ func NewAccount(login string, password string) *Account {
// Service // Service
type SignupOrLoginRequest struct { type SignupOrLoginRequest struct {
Login string `validate:"min=3,max=40,regexp=^[a-zA-Z0-9]*$"` Login string `binding:"min=3,max=40,alphanum"`
Password string `validate:"min=8,max=40"` Password string `binding:"min=8,max=40"`
} }
func (s *Service) Signup(c *gin.Context) { func (s *Service) Signup(c *gin.Context) {
@ -62,10 +61,6 @@ func (s *Service) Signup(c *gin.Context) {
if c.BindJSON(&account) != nil { if c.BindJSON(&account) != nil {
return return
} }
if err := validator.Validate(account); err != nil {
c.AbortWithError(http.StatusExpectationFailed, err)
return
}
var accountExists int64 var accountExists int64
if err := s.DB.Model(&Account{}).Where("login = ?", account.Login).Count(&accountExists).Error; err != nil { if err := s.DB.Model(&Account{}).Where("login = ?", account.Login).Count(&accountExists).Error; err != nil {