validator

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: Apache-2.0 Imports: 7 Imported by: 10

README

justice-input-validation-go

This is AccelByte Justice Golang Input Validation package. This package is extending functionality from govalidator and add some additional rule to it.

Usage

Importing package
import validator "github.com/AccelByte/justice-input-validation-go"
Validating struct from request data model

We can validate a struct that have validation tag literal with validateStruct() method

import validator "github.com/AccelByte/justice-input-validation-go"

// example of a request model
type requestModel struct {
  Name  string `valid:"displayName"`
  Email string `valid:"email"`
}

reqData = requestModel{
    Name: "Jhon Doe",
    Email: "jhon@mail.com",
}

// validating struct
if valid, err := validator.ValidateStruct(reqData); !valid || err {
    // do something when reqData is invalid
}
 
List of available validators with its corresponding function that defined in rules.go file
"tag"                   : IsTag
"language"              : IsLanguage
"topic"                 : IsTopic
"displayName"           : IsDisplayName
"personName"            : IsPersonName
"uuid4WithoutHyphens"   : IsUUID4WithoutHyphens
"permissionResource"    : IsPermissionResource
"path"                  : IsPath
"url"                   : IsURL
"uri"                   : IsURI
"dateTime"              : IsDateTime
"date"                  : IsDate
"jwt"                   : IsJWT
"password"              : IsPassword
"email"                 : IsEmail
"codeChallenge"         : IsCodeChallenge
"notContainWhitespace"  : IsNotContainWhitespace
"containWhitespace"     : IsContainWhitespace
"country"               : IsCountry
"namespace"             : IsNamespace

And of course this package is not limiting the functionality that came from govalidator package, you can use all available validation rules that supported by govalidator package.

Documentation

Index

Constants

View Source
const (
	UUID4WithoutHyphenPattern         = "^[0-9a-f]{12}4[0-9a-f]{3}[89ab][0-9a-f]{15}$"
	LanguagePattern                   = "^[a-zA-Z]+([-]{1}[a-zA-Z]+)*$"
	TagPattern                        = "^[a-zA-Z]+([_:-]{1}[a-zA-Z]+)*$"
	TopicPattern                      = "^[A-Z]+([_]{1}[A-Z]+)*$"
	DisplayNamePattern                = "^[a-zA-Z0-9]+(([',. -][a-zA-Z0-9])?[a-zA-Z0-9]*)*$"
	PersonNamePattern                 = "^[a-zA-Z]+(([',. -][a-zA-Z])?[a-zA-Z]*)*$"
	OWASPEmailPattern                 = `^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,15}$`
	ResourcePermissionPattern         = `^[A-Z]+([:]{1}([A-Z]+|(({[a-zA-Z]+})|[a-zA-Z0-9]+|\*)))*$`
	ResourcePermissionPatternWithUUID = `^[A-Z]+([:]{1}([A-Z]+|(({[a-zA-Z0-9-]+})|[a-zA-Z0-9]+|\*)))*$`
	OWASPURLPattern                   = `` /* 136-byte string literal not displayed */
	ContainWhitespacePattern          = `\s`
	JWTPattern                        = `^([A-Za-z0-9\-_~+\/]+[=]{0,2})\.([A-Za-z0-9\-_~+\/]+[=]{0,2})(?:\.([A-Za-z0-9\-_~+\/]+[=]{0,2}))?$`
	PathPattern                       = `^(\/[a-zA-Z0-9]+)+$`
	CodeChallengePattern              = `^[a-zA-Z0-9-._~]*$`
	ISO8601TimeFormat                 = "2006-01-02"
	OWASPComplexPasswordPattern       = `` /* 224-byte string literal not displayed */
	NamespacePattern                  = `^[a-zA-Z0-9]{1,256}(\-[a-zA-Z0-9]{1,256})?$`
)

Variables

This section is empty.

Functions

func BaseValidator added in v0.0.3

func BaseValidator(validationRule string, input string) bool

BaseValidator is used to extend validate function in GoValidator

func IsCodeChallenge added in v0.0.3

func IsCodeChallenge(str string) bool

func IsContainWhitespace added in v0.0.3

func IsContainWhitespace(str string) bool

func IsCountry added in v0.0.3

func IsCountry(str string) bool

func IsDate

func IsDate(str string) bool

func IsDateTime added in v0.0.3

func IsDateTime(str string) bool

func IsDisplayName

func IsDisplayName(str string) bool

func IsEmail added in v0.0.3

func IsEmail(str string) bool

func IsIn

func IsIn(str string, params ...string) bool

func IsJWT

func IsJWT(str string) bool

func IsLanguage

func IsLanguage(str string) bool

func IsLowerCase

func IsLowerCase(str string) bool

func IsNamespace added in v0.1.0

func IsNamespace(input string) bool

func IsNotContainWhitespace added in v0.0.3

func IsNotContainWhitespace(str string) bool

func IsNumeric

func IsNumeric(str string) bool

func IsPassword

func IsPassword(str string) bool

func IsPath

func IsPath(str string) bool

func IsPermissionResource

func IsPermissionResource(str string) bool

func IsPermissionResourceWithUUID added in v0.0.5

func IsPermissionResourceWithUUID(str string) bool

func IsPersonName added in v0.0.3

func IsPersonName(str string) bool

func IsTag

func IsTag(str string) bool

func IsTopic

func IsTopic(str string) bool

func IsURI added in v0.0.4

func IsURI(str string) bool

func IsURL

func IsURL(str string) bool

func IsUUID4WithoutHyphens

func IsUUID4WithoutHyphens(str string) bool

func StringLength added in v0.0.3

func StringLength(input string, min int, max int) bool

func ValidateStruct

func ValidateStruct(s interface{}) (bool, error)

ValidateStruct is used to check the Struct based on the rule of each field

Types

This section is empty.

Jump to

Keyboard shortcuts

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