chore: update golangci-lint config

This commit is contained in:
Steven
2023-09-17 22:55:13 +08:00
parent 9eb077c4af
commit cd0ea6558d
72 changed files with 272 additions and 187 deletions

View File

@@ -8,9 +8,10 @@ import (
"github.com/labstack/echo/v4"
"github.com/pkg/errors"
"golang.org/x/crypto/bcrypt"
"github.com/usememos/memos/common/util"
"github.com/usememos/memos/store"
"golang.org/x/crypto/bcrypt"
)
// Role is the type of a role.
@@ -404,26 +405,26 @@ func (s *APIV1Service) UpdateUser(c echo.Context) error {
func (create CreateUserRequest) Validate() error {
if len(create.Username) < 3 {
return fmt.Errorf("username is too short, minimum length is 3")
return errors.Errorf("username is too short, minimum length is 3")
}
if len(create.Username) > 32 {
return fmt.Errorf("username is too long, maximum length is 32")
return errors.Errorf("username is too long, maximum length is 32")
}
if len(create.Password) < 3 {
return fmt.Errorf("password is too short, minimum length is 3")
return errors.Errorf("password is too short, minimum length is 3")
}
if len(create.Password) > 512 {
return fmt.Errorf("password is too long, maximum length is 512")
return errors.Errorf("password is too long, maximum length is 512")
}
if len(create.Nickname) > 64 {
return fmt.Errorf("nickname is too long, maximum length is 64")
return errors.Errorf("nickname is too long, maximum length is 64")
}
if create.Email != "" {
if len(create.Email) > 256 {
return fmt.Errorf("email is too long, maximum length is 256")
return errors.Errorf("email is too long, maximum length is 256")
}
if !util.ValidateEmail(create.Email) {
return fmt.Errorf("invalid email format")
return errors.Errorf("invalid email format")
}
}
@@ -432,31 +433,31 @@ func (create CreateUserRequest) Validate() error {
func (update UpdateUserRequest) Validate() error {
if update.Username != nil && len(*update.Username) < 3 {
return fmt.Errorf("username is too short, minimum length is 3")
return errors.Errorf("username is too short, minimum length is 3")
}
if update.Username != nil && len(*update.Username) > 32 {
return fmt.Errorf("username is too long, maximum length is 32")
return errors.Errorf("username is too long, maximum length is 32")
}
if update.Password != nil && len(*update.Password) < 3 {
return fmt.Errorf("password is too short, minimum length is 3")
return errors.Errorf("password is too short, minimum length is 3")
}
if update.Password != nil && len(*update.Password) > 512 {
return fmt.Errorf("password is too long, maximum length is 512")
return errors.Errorf("password is too long, maximum length is 512")
}
if update.Nickname != nil && len(*update.Nickname) > 64 {
return fmt.Errorf("nickname is too long, maximum length is 64")
return errors.Errorf("nickname is too long, maximum length is 64")
}
if update.AvatarURL != nil {
if len(*update.AvatarURL) > 2<<20 {
return fmt.Errorf("avatar is too large, maximum is 2MB")
return errors.Errorf("avatar is too large, maximum is 2MB")
}
}
if update.Email != nil && *update.Email != "" {
if len(*update.Email) > 256 {
return fmt.Errorf("email is too long, maximum length is 256")
return errors.Errorf("email is too long, maximum length is 256")
}
if !util.ValidateEmail(*update.Email) {
return fmt.Errorf("invalid email format")
return errors.Errorf("invalid email format")
}
}