Categorygithub.com/ntopus/validate-go
modulepackage
0.2.2
Repository: https://github.com/ntopus/validate-go.git
Documentation: pkg.go.dev

# README

Validate Go

A struct validator which group in a map and custom errors messages from a simplified Go Validator.

Usage

Registering custom validation func

Example
    validate.RegisterValidation("underAge", underAge, "the :field is too low")
Registering
    // name is the validation name where will be used on struct tags
    // function is the validation function that will receive the field
    // value to be validate
    // message is the custom message when validation failed, use :field
    // in the message and will be replaced by failed field name
   validate.RegisterValidation(name string, function ValidationFunc, message string)

ValidationFunc

    type ValidationFunc func(field IField) bool

IField

   type IField interface {
   	Field() reflect.Value
   }
Validation name usage example
   type Student struct {
   	Name     string `validate:"required"`
   	Email    string `validate:"required,email"`
   	Password string `validate:"required"`
   	Age      int    `validate:"underAge"`
   }

Registering custom message to a validation

Example
    validate.RegisterValidationMessage("underAge", "the :field is too low")
Registering
    validate.RegisterValidationMessage(name string, message string)

Validation

    // data is struct that will be under validation
    // errors is a map[string]string with the failed field 
    // name as key and error message as value
    // ok is a boolean warning the validation status
    errors, ok := validate.Validate(data interface{})

# Functions

No description provided by the author
No description provided by the author
No description provided by the author

# Constants

No description provided by the author
No description provided by the author

# Variables

No description provided by the author
No description provided by the author

# Structs

No description provided by the author

# Interfaces

No description provided by the author

# Type aliases

No description provided by the author