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