chore: remove common error package

This commit is contained in:
Steven
2023-06-20 16:01:13 +08:00
parent df4c09c15b
commit 20884e9370
11 changed files with 68 additions and 140 deletions

View File

@ -2,8 +2,8 @@ package v1
import (
"fmt"
"net/mail"
"github.com/boojack/shortify/common"
"github.com/labstack/echo/v4"
)
@ -57,7 +57,7 @@ func (create UserCreate) Validate() error {
if len(create.Email) < 3 {
return fmt.Errorf("email is too short, minimum length is 6")
}
if !common.ValidateEmail(create.Email) {
if !validateEmail(create.Email) {
return fmt.Errorf("invalid email format")
}
if len(create.Password) < 3 {
@ -104,3 +104,11 @@ func (*APIV1Service) RegisterUserRoutes(g *echo.Group) {
return c.String(200, "GET /user")
})
}
// validateEmail validates the email.
func validateEmail(email string) bool {
if _, err := mail.ParseAddress(email); err != nil {
return false
}
return true
}