validation

package
v0.0.0-...-8ec58fc Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ValidatorUtils = ValidatorUtilsStruct{
	CheckValidator:   make(map[string]string),
	ValidatorMessage: make(map[string]func(vf validator.FieldError) string),
}

Functions

func CamelCaseToReadable

func CamelCaseToReadable(input string) string

func IsAlphaNumericOrSpecial

func IsAlphaNumericOrSpecial(char rune) bool

isAlphaNumericOrSpecial checks if a character is alphanumeric or a valid special character.

func IsValidFileExtension

func IsValidFileExtension(filename string, validExtensions []string) bool

IsValidFileExtension checks if the given file's extension matches one of the valid extensions in the provided list. It returns true if the file extension is in the list of valid extensions, otherwise returns false. The comparison is case-insensitive.

Example usage:

validExtensions := []string{"jpg", "png", "gif"}
isValid := IsValidFileExtension("image.JPG", validExtensions)

func RegisterAllCustomValidators

func RegisterAllCustomValidators(validatorUtils ValidatorUtilsStruct)

func Validate

func Validate(validate *validator.Validate, data any) map[string]string

func ValidateApiIsNilOrNotNil

func ValidateApiIsNilOrNotNil(data map[string]any) error

func ValidateDepreceted

func ValidateDepreceted(validate *validator.Validate, data any) map[string]string

func ValidatePhoneNumber

func ValidatePhoneNumber(phone string) (bool, error)

Types

type ValidatorUtilsStruct

type ValidatorUtilsStruct struct {
	CheckValidator   map[string]string
	ValidatorMessage map[string]func(vf validator.FieldError) string
}

func (*ValidatorUtilsStruct) RegisterCustomNameValidatorAndMessage

func (v *ValidatorUtilsStruct) RegisterCustomNameValidatorAndMessage(
	nameValidator string,
	customMessage func(vf validator.FieldError) string,
) error

func (*ValidatorUtilsStruct) RegisterCustomValidatorAndMessage

func (v *ValidatorUtilsStruct) RegisterCustomValidatorAndMessage(
	validate *validator.Validate,
	customValidate func(fl validator.FieldLevel) bool,
	nameValidator string,
	customMessage func(vf validator.FieldError) string,
) error

Jump to

Keyboard shortcuts

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