v2

package module
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2024 License: MIT Imports: 13 Imported by: 0

README

GoDoc License Go Report Card Go CI codecov

Checker

Checker is a lightweight Go library designed to validate user input efficiently. It supports validation of both struct fields and individual input values.

While there are numerous validation libraries available, Checker stands out due to its simplicity and lack of external dependencies. This makes it an ideal choice for developers who prefer to minimize dependencies and maintain control over their tools. Checker is straightforward to use and effectively meets your validation needs.

Usage

To begin using the Checker library, install it with the following command:

go get github.com/cinar/checker/v2

Then, import the library into your source file as shown below:

import (
	checker "github.com/cinar/checker/v2"
)
Validating User Input Stored in a Struct

Checker can validate user input stored in a struct by listing the checkers in the struct tags for each field. Here is an example:

type Person struct {
	Name string `checkers:"trim required"`
}

person := &Person{
	Name: " Onur Cinar ",
}

errors, valid := checker.CheckStruct(person)
if !valid {
	// Handle validation errors
}
Validating Individual User Input with Multiple Checkers

You can also validate individual user input by calling checker functions directly. Here is an example:

name := " Onur Cinar "

name, err := checker.Check(name, checker.Trim, checker.Required)
if err != nil {
	// Handle validation error
}

The checkers and normalizers can also be provided through a config string. Here is an example:

name := " Onur Cinar "

name, err := checker.CheckWithConfig(name, "trim requied")
if err != nil {
	// Handle validation error
}

Validating Individual User Input

For simpler validation, you can call individual checker functions. Here is an example:

name := "Onur Cinar"

err := checker.IsRequired(name)
if err != nil {
	// Handle validation error
}

Normalizers and Checkers

Checkers validate user input, while normalizers transform it into a preferred format. For example, a normalizer can trim spaces from a string or convert it to title case.

Although combining checkers and normalizers into a single library might seem unconventional, using them together can be beneficial. They can be mixed in any order when defining validation steps. For instance, you can use the trim normalizer with the required checker to first trim the input and then ensure it is provided. Here is an example:

type Person struct {
	Name string `checkers:"trim required"`
}

Checkers Provided

  • ascii: Ensures the string contains only ASCII characters.
  • alphanumeric: Ensures the string contains only letters and numbers.
  • credit-card: Ensures the string is a valid credit card number.
  • cidr: Ensures the string is a valid CIDR notation.
  • digits: Ensures the string contains only digits.
  • email: Ensures the string is a valid email address.
  • fqdn: Ensures the string is a valid fully qualified domain name.
  • gte: Ensures the value is greater than or equal to the specified number.
  • hex: Ensures the string contains only hexadecimal digits.
  • ip: Ensures the string is a valid IP address.
  • ipv4: Ensures the string is a valid IPv4 address.
  • ipv6: Ensures the string is a valid IPv6 address.
  • isbn: Ensures the string is a valid ISBN.
  • lte: Ensures the value is less than or equal to the specified number.
  • luhn: Ensures the string is a valid LUHN number.
  • mac: Ensures the string is a valid MAC address.
  • max-len: Ensures the length of the given value (string, slice, or map) is at most n.
  • min-len: Ensures the length of the given value (string, slice, or map) is at least n.
  • required Ensures the value is provided.
  • regexp Ensured the string matches the pattern.
  • url: Ensures the string is a valid URL.

Normalizers Provided

  • lower: Converts the string to lowercase.
  • title: Converts the string to title case.
  • trim-left: Trims whitespace from the left side of the string.
  • trim-right: Trims whitespace from the right side of the string.
  • trim: Trims whitespace from both sides of the string.
  • upper: Converts the string to uppercase.
  • html-escape: Escapes special characters in the string for HTML.
  • html-unescape: Unescapes special characters in the string for HTML.
  • url-escape: Escapes special characters in the string for URLs.
  • url-unescape: Unescapes special characters in the string for URLs.

Custom Checkers and Normalizers

You can define custom checkers or normalizers and register them for use in your validation logic. Here is an example of how to create and register a custom checker:

checker.RegisterMaker("is-fruit", func(params string) v2.CheckFunc[reflect.Value] {
	return func(value reflect.Value) (reflect.Value, error) {
		stringValue := value.Interface().(string)

		if stringValue == "apple" || stringValue == "banana" {
			return value, nil
		}

		return value, v2.NewCheckError("NOT_FRUIT")
	}
})

In this example, the custom checker is-fruit checks if the input value is either "apple" or "banana". If the value is not one of these, it returns an error.

Once registered, you can use your custom checker in struct tags just like the built-in checkers:

type Item struct {
	Name string `checkers:"is-fruit"`
}

item := &Item{
	Name: "banana",
}

errors, valid := v2.CheckStruct(item)
if !valid {
	fmt.Println(errors)
}

In this example, the is-fruit checker is used to validate that the Name field of the Item struct is either "apple" or "banana".

Slice and Item Level Checkers

When adding checker struct tags to a slice, you can use the @ prefix to indicate that the checker should be applied to the slice itself. Checkers without the @ prefix will be applied to the individual items within the slice. Here is an example:

type Person struct {
	Name   string   `checkers:"required"`
	Emails []string `checkers:"@max-len:2 max-len:64"`
}

In this example:

  • @max-len:2 ensures that the Emails slice itself has at most two items.
  • max-len:64 ensures that each email string within the Emails slice has a maximum length of 64 characters.

Localized Error Messages

When validation fails, Checker returns an error. By default, the Error() function provides a human-readable error message in en-US locale.

_, err := checker.IsEmail("abcd")
if err != nil {
	fmt.Println(err)
	// Output: Not a valid email address.
}

To get error messages in other languages, use the ErrorWithLocale() function. By default, only en-US is registered. You can register additional languages by calling RegisterLocale.

// Register de-DE localized error messages.
checker.RegisterLocale(locales.DeDE, locales.DeDEMessages)

_, err := checker.IsEmail("abcd")
if err != nil {
	fmt.Println(err.ErrorWithLocale(locales.DeDE))
	// Output: Keine gültige E-Mail-Adresse.
}

You can also customize existing error messages or add new ones to locales.EnUSMessages and other locale maps.

// Register the en-US localized error message for the custom NOT_FRUIT error code.
locales.EnUSMessages["NOT_FRUIT"] = "Not a fruit name."

errors, valid := v2.CheckStruct(item)
if !valid {
	fmt.Println(errors)
	// Output: map[Name:Not a fruit name.]
}

Error messages are generated using Golang template functions, allowing them to include variables.

// Custrom checker error containing the item name.
err := checker.NewCheckErrorWithData(
	"NOT_FRUIT",
	map[string]interface{}{
		"name": "abcd",
	},
)

// Register the en-US localized error message for the custom NOT_FRUIT error code.
locales.EnUSMessages["NOT_FRUIT"] = "Name {{ .name }} is not a fruit name."

errors, valid := v2.CheckStruct(item)
if !valid {
	fmt.Println(errors)
	// Output: map[Name:Name abcd is not a fruit name.]
}

Contributing to the Project

Anyone can contribute to Checkers library. Please make sure to read our Contributor Covenant Code of Conduct guide first. Follow the How to Contribute to Checker to contribute.

License

This library is free to use, modify, and distribute under the terms of the MIT license. The full license text can be found in the LICENSE file.

The MIT license is a permissive license that allows you to do almost anything with the library, as long as you retain the copyright notice and the license text. This means that you can use the library in commercial products, modify it, and redistribute it without having to ask for permission from the authors.

The LICENSE file is located in the root directory of the library. You can open it in a text editor to read the full license text.

Documentation

Overview

Package v2 Checker is a Go library for validating user input through checker rules provided in struct tags.

Index

Examples

Constants

View Source
const (
	// DefaultLocale is the default locale.
	DefaultLocale = locales.EnUS
)

Variables

View Source
var (
	// ErrGte indicates that the value is not greater than or equal to the given value.
	ErrGte = NewCheckError("NOT_GTE")
)
View Source
var (
	// ErrLte indicates that the value is not less than or equal to the given value.
	ErrLte = NewCheckError("NOT_LTE")
)
View Source
var (
	// ErrMaxLen indicates that the value's length is greater than the specified maximum.
	ErrMaxLen = NewCheckError("NOT_MAX_LEN")
)
View Source
var (
	// ErrMinLen indicates that the value's length is less than the specified minimum.
	ErrMinLen = NewCheckError("NOT_MIN_LEN")
)
View Source
var (
	// ErrNotASCII indicates that the given string contains non-ASCII characters.
	ErrNotASCII = NewCheckError("NOT_ASCII")
)
View Source
var (
	// ErrNotAlphanumeric indicates that the given string contains non-alphanumeric characters.
	ErrNotAlphanumeric = NewCheckError("NOT_ALPHANUMERIC")
)
View Source
var (
	// ErrNotCIDR indicates that the given value is not a valid CIDR.
	ErrNotCIDR = NewCheckError("NOT_CIDR")
)
View Source
var (
	// ErrNotCreditCard indicates that the given value is not a valid credit card number.
	ErrNotCreditCard = NewCheckError("NOT_CREDIT_CARD")
)
View Source
var (
	// ErrNotDigits indicates that the given value is not a valid digits string.
	ErrNotDigits = NewCheckError("NOT_DIGITS")
)
View Source
var (
	// ErrNotEmail indicates that the given value is not a valid email address.
	ErrNotEmail = NewCheckError("NOT_EMAIL")
)
View Source
var (
	// ErrNotFQDN indicates that the given value is not a valid FQDN.
	ErrNotFQDN = NewCheckError("FQDN")
)
View Source
var (
	// ErrNotHex indicates that the given string contains hex characters.
	ErrNotHex = NewCheckError("NOT_HEX")
)
View Source
var (
	// ErrNotIP indicates that the given value is not a valid IP address.
	ErrNotIP = NewCheckError("NOT_IP")
)
View Source
var (
	// ErrNotIPv4 indicates that the given value is not a valid IPv4 address.
	ErrNotIPv4 = NewCheckError("NOT_IPV4")
)
View Source
var (
	// ErrNotIPv6 indicates that the given value is not a valid IPv6 address.
	ErrNotIPv6 = NewCheckError("NOT_IPV6")
)
View Source
var (
	// ErrNotISBN indicates that the given value is not a valid ISBN.
	ErrNotISBN = NewCheckError("NOT_ISBN")
)
View Source
var (
	// ErrNotLUHN indicates that the given value is not a valid LUHN number.
	ErrNotLUHN = NewCheckError("NOT_LUHN")
)
View Source
var (
	// ErrNotMAC indicates that the given value is not a valid MAC address.
	ErrNotMAC = NewCheckError("NOT_MAC")
)
View Source
var ErrNotMatch = NewCheckError("REGEXP")

ErrNotMatch indicates that the given string does not match the regexp pattern.

View Source
var (
	// ErrNotURL indicates that the given value is not a valid URL.
	ErrNotURL = NewCheckError("NOT_URL")
)
View Source
var (
	// ErrRequired indicates that a required value was missing.
	ErrRequired = NewCheckError("REQUIRED")
)

Functions

func Check

func Check[T any](value T, checks ...CheckFunc[T]) (T, error)

Check applies the given check functions to a value sequentially. It returns the final value and the first encountered error, if any.

Example
package main

import (
	"fmt"

	v2 "github.com/cinar/checker/v2"
)

func main() {
	name := "    Onur Cinar    "

	name, err := v2.Check(name, v2.TrimSpace, v2.Required)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(name)
}
Output:

Onur Cinar

func CheckStruct

func CheckStruct(st any) (map[string]error, bool)

CheckStruct checks the given struct based on the validation rules specified in the "checker" tag of each struct field. It returns a map of field names to their corresponding errors, and a boolean indicating if all checks passed.

Example
package main

import (
	"fmt"

	v2 "github.com/cinar/checker/v2"
)

func main() {
	type Person struct {
		Name string `checkers:"trim required"`
	}

	person := &Person{
		Name: "    Onur Cinar    ",
	}

	errs, ok := v2.CheckStruct(person)
	if !ok {
		fmt.Println(errs)
		return
	}

	fmt.Println(person.Name)
}
Output:

Onur Cinar

func CheckWithConfig

func CheckWithConfig[T any](value T, config string) (T, error)

CheckWithConfig applies the check functions specified by the config string to the given value. It returns the modified value and the first encountered error, if any.

func HTMLEscape

func HTMLEscape(value string) (string, error)

HTMLEscape applies HTML escaping to special characters.

func HTMLUnescape

func HTMLUnescape(value string) (string, error)

HTMLUnescape applies HTML unescaping to special characters.

func IsASCII

func IsASCII(value string) (string, error)

IsASCII checks if the given string consists of only ASCII characters.

Example
package main

import (
	"fmt"

	v2 "github.com/cinar/checker/v2"
)

func main() {
	_, err := v2.IsASCII("Checker")
	if err != nil {
		fmt.Println(err)
	}
}
Output:

func IsAlphanumeric

func IsAlphanumeric(value string) (string, error)

IsAlphanumeric checks if the given string consists of only alphanumeric characters.

Example
package main

import (
	"fmt"

	v2 "github.com/cinar/checker/v2"
)

func main() {
	_, err := v2.IsAlphanumeric("ABcd1234")
	if err != nil {
		fmt.Println(err)
	}
}
Output:

func IsAmexCreditCard

func IsAmexCreditCard(number string) (string, error)

IsAmexCreditCard checks if the given valie is a valid AMEX credit card.

Example
package main

import (
	v2 "github.com/cinar/checker/v2"
)

func main() {
	_, err := v2.IsAmexCreditCard("378282246310005")

	if err != nil {
		// Send the errors back to the user
	}
}
Output:

func IsAnyCreditCard

func IsAnyCreditCard(number string) (string, error)

IsAnyCreditCard checks if the given value is a valid credit card number.

Example
package main

import (
	v2 "github.com/cinar/checker/v2"
)

func main() {
	_, err := v2.IsAnyCreditCard("6011111111111117")

	if err != nil {
		// Send the errors back to the user
	}
}
Output:

func IsCIDR

func IsCIDR(value string) (string, error)

IsCIDR checks if the value is a valid CIDR notation IP address and prefix length.

Example
package main

import (
	"fmt"

	v2 "github.com/cinar/checker/v2"
)

func main() {
	_, err := v2.IsCIDR("2001:db8::/32")
	if err != nil {
		fmt.Println(err)
	}
}
Output:

func IsDigits

func IsDigits(value string) (string, error)

IsDigits checks if the value contains only digit characters.

Example
package main

import (
	"fmt"

	v2 "github.com/cinar/checker/v2"
)

func main() {
	_, err := v2.IsDigits("123456")
	if err != nil {
		fmt.Println(err)
	}
}
Output:

func IsDinersCreditCard

func IsDinersCreditCard(number string) (string, error)

IsDinersCreditCard checks if the given valie is a valid Diners credit card.

Example
package main

import (
	v2 "github.com/cinar/checker/v2"
)

func main() {
	_, err := v2.IsDinersCreditCard("36227206271667")

	if err != nil {
		// Send the errors back to the user
	}
}
Output:

func IsDiscoverCreditCard

func IsDiscoverCreditCard(number string) (string, error)

IsDiscoverCreditCard checks if the given valie is a valid Discover credit card.

Example
package main

import (
	v2 "github.com/cinar/checker/v2"
)

func main() {
	_, err := v2.IsDiscoverCreditCard("6011111111111117")

	if err != nil {
		// Send the errors back to the user
	}
}
Output:

func IsEmail

func IsEmail(value string) (string, error)

IsEmail checks if the value is a valid email address.

Example
package main

import (
	"fmt"

	v2 "github.com/cinar/checker/v2"
)

func main() {
	_, err := v2.IsEmail("test@example.com")
	if err != nil {
		fmt.Println(err)
	}
}
Output:

func IsFQDN

func IsFQDN(value string) (string, error)

IsFQDN checks if the value is a valid fully qualified domain name (FQDN).

Example
package main

import (
	"fmt"

	v2 "github.com/cinar/checker/v2"
)

func main() {
	_, err := v2.IsFQDN("example.com")
	if err != nil {
		fmt.Println(err)
	}
}
Output:

func IsGte added in v2.0.1

func IsGte[T cmp.Ordered](value, n T) (T, error)

IsGte checks if the value is greater than or equal to the given value.

func IsHex

func IsHex(value string) (string, error)

IsHex checks if the given string consists of only hex characters.

Example
package main

import (
	"fmt"

	v2 "github.com/cinar/checker/v2"
)

func main() {
	_, err := v2.IsHex("0123456789abcdefABCDEF")
	if err != nil {
		fmt.Println(err)
	}
}
Output:

func IsIP

func IsIP(value string) (string, error)

IsIP checks if the value is a valid IP address.

Example
package main

import (
	"fmt"

	v2 "github.com/cinar/checker/v2"
)

func main() {
	_, err := v2.IsIP("192.168.1.1")
	if err != nil {
		fmt.Println(err)
	}
}
Output:

func IsIPv4

func IsIPv4(value string) (string, error)

IsIPv4 checks if the value is a valid IPv4 address.

Example
package main

import (
	"fmt"

	v2 "github.com/cinar/checker/v2"
)

func main() {
	_, err := v2.IsIPv4("192.168.1.1")
	if err != nil {
		fmt.Println(err)
	}
}
Output:

func IsIPv6

func IsIPv6(value string) (string, error)

IsIPv6 checks if the value is a valid IPv6 address.

Example
package main

import (
	"fmt"

	v2 "github.com/cinar/checker/v2"
)

func main() {
	_, err := v2.IsIPv6("2001:db8::1")
	if err != nil {
		fmt.Println(err)
	}
}
Output:

func IsISBN

func IsISBN(value string) (string, error)

IsISBN checks if the value is a valid ISBN-10 or ISBN-13.

Example
package main

import (
	"fmt"

	v2 "github.com/cinar/checker/v2"
)

func main() {
	_, err := v2.IsISBN("1430248270")
	if err != nil {
		fmt.Println(err)
	}
}
Output:

func IsJcbCreditCard

func IsJcbCreditCard(number string) (string, error)

IsJcbCreditCard checks if the given valie is a valid JCB 15 credit card.

Example
package main

import (
	v2 "github.com/cinar/checker/v2"
)

func main() {
	_, err := v2.IsJcbCreditCard("3530111333300000")

	if err != nil {
		// Send the errors back to the user
	}
}
Output:

func IsLUHN

func IsLUHN(value string) (string, error)

IsLUHN checks if the value is a valid LUHN number.

Example
package main

import (
	"fmt"

	v2 "github.com/cinar/checker/v2"
)

func main() {
	_, err := v2.IsLUHN("4012888888881881")
	if err != nil {
		fmt.Println(err)
	}
}
Output:

func IsLte added in v2.0.1

func IsLte[T cmp.Ordered](value, n T) (T, error)

IsLte checks if the value is less than or equal to the given value.

func IsMAC

func IsMAC(value string) (string, error)

IsMAC checks if the value is a valid MAC address.

Example
package main

import (
	"fmt"

	v2 "github.com/cinar/checker/v2"
)

func main() {
	_, err := v2.IsMAC("00:1A:2B:3C:4D:5E")
	if err != nil {
		fmt.Println(err)
	}
}
Output:

func IsMasterCardCreditCard

func IsMasterCardCreditCard(number string) (string, error)

IsMasterCardCreditCard checks if the given valie is a valid MasterCard credit card.

Example
package main

import (
	v2 "github.com/cinar/checker/v2"
)

func main() {
	_, err := v2.IsMasterCardCreditCard("5555555555554444")

	if err != nil {
		// Send the errors back to the user
	}
}
Output:

func IsRegexp

func IsRegexp(expression, value string) (string, error)

IsRegexp checks if the given string matches the given regexp expression.

Example
package main

import (
	"fmt"

	v2 "github.com/cinar/checker/v2"
)

func main() {
	_, err := v2.IsRegexp("^[0-9a-fA-F]+$", "ABcd1234")
	if err != nil {
		fmt.Println(err)
	}
}
Output:

func IsURL

func IsURL(value string) (string, error)

IsURL checks if the value is a valid URL.

Example
package main

import (
	"fmt"

	v2 "github.com/cinar/checker/v2"
)

func main() {
	_, err := v2.IsURL("https://example.com")
	if err != nil {
		fmt.Println(err)
	}
}
Output:

func IsUnionPayCreditCard

func IsUnionPayCreditCard(number string) (string, error)

IsUnionPayCreditCard checks if the given valie is a valid UnionPay credit card.

Example
package main

import (
	v2 "github.com/cinar/checker/v2"
)

func main() {
	_, err := v2.IsUnionPayCreditCard("6200000000000005")

	if err != nil {
		// Send the errors back to the user
	}
}
Output:

func IsVisaCreditCard

func IsVisaCreditCard(number string) (string, error)

IsVisaCreditCard checks if the given valie is a valid Visa credit card.

Example
package main

import (
	v2 "github.com/cinar/checker/v2"
)

func main() {
	_, err := v2.IsVisaCreditCard("4111111111111111")

	if err != nil {
		// Send the errors back to the user
	}
}
Output:

func Lower

func Lower(value string) (string, error)

Lower maps all Unicode letters in the given value to their lower case.

func ReflectCheckWithConfig

func ReflectCheckWithConfig(value reflect.Value, config string) (reflect.Value, error)

ReflectCheckWithConfig applies the check functions specified by the config string to the given reflect.Value. It returns the modified reflect.Value and the first encountered error, if any.

func RegisterLocale

func RegisterLocale(locale string, messages map[string]string)

RegisterLocale registers the localized error messages for the given locale.

func RegisterMaker

func RegisterMaker(name string, maker MakeCheckFunc)

RegisterMaker registers a new maker function with the given name.

Example
package main

import (
	"fmt"
	"reflect"

	"github.com/cinar/checker/v2/locales"

	v2 "github.com/cinar/checker/v2"
)

func main() {
	locales.EnUSMessages["NOT_FRUIT"] = "Not a fruit name."

	v2.RegisterMaker("is-fruit", func(params string) v2.CheckFunc[reflect.Value] {
		return func(value reflect.Value) (reflect.Value, error) {
			stringValue := value.Interface().(string)

			if stringValue == "apple" || stringValue == "banana" {
				return value, nil
			}

			return value, v2.NewCheckError("NOT_FRUIT")
		}
	})

	type Item struct {
		Name string `checkers:"is-fruit"`
	}

	person := &Item{
		Name: "banana",
	}

	err, ok := v2.CheckStruct(person)
	if !ok {
		fmt.Println(err)
	}
}
Output:

func Required

func Required[T any](value T) (T, error)

Required checks if the given value of type T is its zero value. It returns an error if the value is zero.

func Title

func Title(value string) (string, error)

Title returns the value of the string with the first letter of each word in upper case.

func TrimLeft

func TrimLeft(value string) (string, error)

TrimLeft returns the value of the string with whitespace removed from the beginning.

func TrimRight

func TrimRight(value string) (string, error)

TrimRight returns the value of the string with whitespace removed from the end.

func TrimSpace

func TrimSpace(value string) (string, error)

TrimSpace returns the value of the string with whitespace removed from both ends.

func URLEscape

func URLEscape(value string) (string, error)

URLEscape applies URL escaping to special characters.

func URLUnescape

func URLUnescape(value string) (string, error)

URLUnescape applies URL unescaping to special characters.

func Upper

func Upper(value string) (string, error)

Upper maps all Unicode letters in the given value to their upper case.

Types

type CheckError

type CheckError struct {
	// Code is the error code.
	Code string

	// data is the error data.
	Data map[string]interface{}
}

CheckError defines the check error.

func NewCheckError

func NewCheckError(code string) *CheckError

NewCheckError creates a new check error with the given code.

func NewCheckErrorWithData

func NewCheckErrorWithData(code string, data map[string]interface{}) *CheckError

NewCheckErrorWithData creates a new check error with the given code and data.

func (*CheckError) Error

func (c *CheckError) Error() string

Error returns the error message for the check.

func (*CheckError) ErrorWithLocale

func (c *CheckError) ErrorWithLocale(locale string) string

ErrorWithLocale returns the localized error message for the check with the given locale.

func (*CheckError) Is

func (c *CheckError) Is(target error) bool

Is reports whether the check error is the same as the target error.

type CheckFunc

type CheckFunc[T any] func(value T) (T, error)

CheckFunc is a function that takes a value of type T and performs a check on it. It returns the resulting value and any error that occurred during the check.

func MakeRegexpChecker

func MakeRegexpChecker(expression string, invalidError error) CheckFunc[reflect.Value]

MakeRegexpChecker makes a regexp checker for the given regexp expression with the given invalid result.

func MaxLen

func MaxLen[T any](n int) CheckFunc[T]

MaxLen checks if the length of the given value (string, slice, or map) is at most n. Returns an error if the length is greater than n.

func MinLen

func MinLen[T any](n int) CheckFunc[T]

MinLen checks if the length of the given value (string, slice, or map) is at least n. Returns an error if the length is less than n.

type MakeCheckFunc

type MakeCheckFunc func(params string) CheckFunc[reflect.Value]

MakeCheckFunc is a function that returns a check function using the given params.

Directories

Path Synopsis
Package locales provides the localized error messages for the check errors.
Package locales provides the localized error messages for the check errors.

Jump to

Keyboard shortcuts

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