-
Notifications
You must be signed in to change notification settings - Fork 402
/
validation.go
52 lines (39 loc) · 1.27 KB
/
validation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package console
import (
"strings"
"github.com/zeebo/errs"
)
const (
passMinLength = 6
)
// ErrValidation validation related error class
var ErrValidation = errs.Class("validation error")
// validationError is slice of ErrValidation class errors
type validationErrors []error
// Add new ErrValidation err
func (validation *validationErrors) Add(format string, args ...interface{}) {
*validation = append(*validation, ErrValidation.New(format, args...))
}
// AddWrap adds new ErrValidation wrapped err
func (validation *validationErrors) AddWrap(err error) {
*validation = append(*validation, ErrValidation.Wrap(err))
}
// Combine returns combined validation errors
func (validation *validationErrors) Combine() error {
return errs.Combine(*validation...)
}
// validatePassword validates password
func validatePassword(pass string) error {
var errs validationErrors
if len(pass) < passMinLength {
errs.Add(passwordIncorrectErrMsg, passMinLength)
}
return errs.Combine()
}
// normalizeEmail converts emails with different casing into equal strings
// Note: won't work with µıſͅςϐϑϕϖϰϱϵᲀᲁᲂᲃᲄᲅᲆᲇᲈẛι
func normalizeEmail(s string) string {
return strings.ToLower(s)
}