Documentation ¶
Index ¶
Constants ¶
View Source
const ( // RegexpTag indicates that the regexp must be valide. RegexpTag = "regexp" // NameTag contains the rule to validate the user's name. NameTag = "name" // UserNameTag contains the rule to validate the user's username. UserNameTag = "username" // UserPasswordTag contains the rule to validate the user's password. UserPasswordTag = "password" // DeviceNameTag contains the rule to validate the device's name. DeviceNameTag = "device_name" )
Variables ¶
View Source
var ( ErrStructureInvalid = errors.New("invalid structure") ErrVarInvalid = errors.New("invalid var") )
View Source
var Rules = []Rule{ { Tag: RegexpTag, Handler: func(field validator.FieldLevel) bool { _, err := regexp.Compile(field.Field().String()) return err == nil }, Error: fmt.Errorf("the regexp is invalid"), }, { Tag: NameTag, Handler: func(field validator.FieldLevel) bool { return regexp.MustCompile(`^(.){1,64}$`).MatchString(field.Field().String()) }, Error: fmt.Errorf("the name must be between 1 and 64 characters"), }, { Tag: UserNameTag, Handler: func(field validator.FieldLevel) bool { return regexp.MustCompile(`^([a-z0-9-_.@]){3,32}$`).MatchString(field.Field().String()) }, Error: fmt.Errorf("the username must be between 3 and 32 characters, and can only contain letters, numbers, and the following characters: -_.@"), }, { Tag: UserPasswordTag, Handler: func(field validator.FieldLevel) bool { return regexp.MustCompile(`^(.){5,32}$`).MatchString(field.Field().String()) }, Error: fmt.Errorf("the password cannot be empty and must be between 5 and 32 characters"), }, { Tag: DeviceNameTag, Handler: func(field validator.FieldLevel) bool { return regexp.MustCompile(`^([a-z0-9_-]){1,64}$`).MatchString(field.Field().String()) }, Error: fmt.Errorf("the device name can only contain `_`, `-` and alpha numeric characters"), }, }
Rules is a slice that contains all validation rules.
Functions ¶
This section is empty.
Types ¶
type Tag ¶ added in v0.14.0
type Tag string
Tag is the rule used to validate a variable or a structure's field.
type Validator ¶ added in v0.10.9
type Validator struct {
Validate *validator.Validate
}
Validator is the ShellHub validator. It uses the go-playground/validator package internally and add custom validation rules for ShellHub types.
func New ¶ added in v0.10.9
func New() *Validator
New creates a new ShellHub validator.
The ShellHub validator contains custom validation rules for ShellHub types.
Click to show internal directories.
Click to hide internal directories.