validator

package
v0.11.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2023 License: Apache-2.0 Imports: 9 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// TagRegexp is the tag used to validate a regexp.
	TagRegexp = "regexp"
	// TagUsername is the tag used to validate ShellHub's username.
	TagUsername = "username"
)

Variables

View Source
var ErrInvalidError = errors.New("this error is not from a field validation")
View Source
var ErrInvalidFields = errors.New("invalid fields")

Functions

func FormatUser added in v0.8.0

func FormatUser(user *models.User)

FormatUser apply some formation rules to a models.User and encrypt the password.

func GetInstance added in v0.10.9

func GetInstance() *validator.Validate

func GetInvalidFieldsFromErr added in v0.10.9

func GetInvalidFieldsFromErr(err error) ([]string, error)

GetInvalidFieldsFromErr gets the invalids frields from a error returned by Struct function.

func GetInvalidFieldsValues added in v0.9.2

func GetInvalidFieldsValues(err error) (map[string]interface{}, error)

GetInvalidFieldsValues receive a structure validation error and return a map with invalid fields and values.

func HashPassword added in v0.8.0

func HashPassword(password string) string

func ValidateField added in v0.9.1

func ValidateField(structure interface{}, field, value string) bool

ValidateField validates if a structure's field is valid.

func ValidateFieldEmail added in v0.9.0

func ValidateFieldEmail(email string) bool

ValidateFieldEmail validate the data for the field Email from structure models.UserData.

func ValidateFieldPassword added in v0.9.0

func ValidateFieldPassword(password string) bool

ValidateFieldPassword validate the data for the field Password from structure models.UserPassword.

func ValidateFieldTag added in v0.9.0

func ValidateFieldTag(tag string) bool

ValidateFieldTag validate the data for the field Tag from structure models.Device.

func ValidateFieldUsername added in v0.9.0

func ValidateFieldUsername(username string) bool

ValidateFieldUsername validate the data for the field Username from structure models.UserData.

func ValidateStruct added in v0.7.3

func ValidateStruct(data interface{}) ([]string, error)

func ValidateStructFields added in v0.9.2

func ValidateStructFields(data interface{}) (map[string]interface{}, error)

func ValidateVar added in v0.7.3

func ValidateVar(data interface{}, tag string) ([]string, error)

Types

type Validator added in v0.10.9

type Validator struct {
	Validate *validator.Validate
}

func New added in v0.10.9

func New() *Validator

New creates a new ShellHub validator.

The ShellHub validator contains validations rules to name, username, email, password, etc.

func (*Validator) Struct added in v0.10.9

func (v *Validator) Struct(structure interface{}) (bool, error)

Struct validates a structure using ShellHub validation's tags.

func (*Validator) Var added in v0.10.9

func (v *Validator) Var(value, tags string) (bool, error)

Var validates a variable using a ShellHub validation's tags.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL