storj/satellite/console/validation.go

54 lines
1.2 KiB
Go
Raw Normal View History

2019-01-24 16:26:36 +00:00
// Copyright (C) 2019 Storj Labs, Inc.
2018-11-29 16:23:44 +00:00
// See LICENSE for copying information.
package console
2018-11-29 16:23:44 +00:00
import (
"github.com/zeebo/errs"
)
const (
passMinLength = 6
2018-11-29 16:23:44 +00:00
)
// ErrValidation validation related error class.
2018-11-29 16:23:44 +00:00
var ErrValidation = errs.Class("validation error")
// validationError is slice of ErrValidation class errors.
2018-11-29 16:23:44 +00:00
type validationErrors []error
// Addf adds a new ErrValidation error to validation.
func (validation *validationErrors) Addf(format string, args ...interface{}) {
2018-11-30 13:04:59 +00:00
*validation = append(*validation, ErrValidation.New(format, args...))
2018-11-29 16:23:44 +00:00
}
// AddWrap adds new ErrValidation wrapped err.
2018-11-29 16:23:44 +00:00
func (validation *validationErrors) AddWrap(err error) {
*validation = append(*validation, ErrValidation.Wrap(err))
}
// Combine returns combined validation errors.
2018-11-29 16:23:44 +00:00
func (validation *validationErrors) Combine() error {
return errs.Combine(*validation...)
2018-11-29 16:23:44 +00:00
}
// ValidatePassword validates password.
func ValidatePassword(pass string) error {
var errs validationErrors
if len(pass) < passMinLength {
errs.Addf(passwordIncorrectErrMsg, passMinLength)
}
return errs.Combine()
}
// ValidateFullName validates full name.
func ValidateFullName(name string) error {
if name == "" {
return errs.New("full name can not be empty")
}
return nil
}