validator

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

This package provides a simple validation library for Go applications. Validator is the main struct that holds the validation errors. It has a Valid method that returns true if there are no errors, and an AddError method to add a new error to the map. Besides the Validator struct, the package also provides a few validation functions like NotEmpty, GreaterThenEquals, and LowerThenEquals.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GreaterThenEquals

func GreaterThenEquals(v *Validator, field string, value int, min int)

GreaterThenEquals checks if a value is greater then or equal to a minimum value.

func LowerThenEquals

func LowerThenEquals(v *Validator, field string, value int, max int)

LowerThenEquals checks if a value is lower then or equal to a maximum value.

func NotEmpty

func NotEmpty(v *Validator, field, value string)

NotEmpty checks if a string is empty.

Types

type Validator

type Validator struct {
	Errors map[string]string // Map of validation errors
}

Validator holds the validation errors.

func New

func New() *Validator

New creates a new instance of the Validator struct.

func (*Validator) AddError

func (v *Validator) AddError(key, message string)

AddError adds a new error to the map.

func (*Validator) Valid

func (v *Validator) Valid() bool

Valid returns true if there are no errors.

Jump to

Keyboard shortcuts

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