validators

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: LGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package validators provides functions to validate input without boilerplate.

Example
err := Validate(
	WithTransactionType("a"),
	WithTransactionID(validTransactionID),
	WithAmount(1000, true),
	WithCurrency(types.CurrencyMDL),
	WithClientIPAddress("127.0.0.1"),
	WithLanguage(types.LanguageEnglish),
	WithBillerClientID("biller", true),
	WithPerspayeeExpiry("1224"),
	WithDescription("description"))
if err != nil {
	// Validation failed
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Validate

func Validate(validators ...FieldValidator) error

Validate runs the argument functions until one of them returns an error. Use any of the With... functions as arguments.

Types

type FieldValidator

type FieldValidator func() error

FieldValidator is the function used as argument to Validate.

func WithAmount

func WithAmount(amount uint, required bool) FieldValidator

WithAmount verifies that amount is at most 12 digits; not 0, if required.

func WithBillerClientID

func WithBillerClientID(billerClientID string, required bool) FieldValidator

WithBillerClientID verifies that billerClientID is at most 49 characters; not empty, if required.

func WithClientIPAddress

func WithClientIPAddress(address string) FieldValidator

WithClientIPAddress verifies that address is a valid IP address.

func WithCurrency

func WithCurrency(currency types.Currency) FieldValidator

WithCurrency verifies that currency is a 3 digit non-negative integer.

func WithDescription

func WithDescription(description string) FieldValidator

WithDescription verifies that description is at most 125 characters.

func WithLanguage

func WithLanguage(language types.Language) FieldValidator

WithLanguage verifies that language is a non-empty string, with at most 32 characters.

func WithPerspayeeExpiry

func WithPerspayeeExpiry(prespayeeExpiry string) FieldValidator

WithPerspayeeExpiry verifies that prespayeeExpiry is 4 characters, first 2 being a number between 1 and 12, second 2 being a non-negative integer.

func WithTransactionID

func WithTransactionID(transactionID string) FieldValidator

WithTransactionID verifies that transactionID is 28 base64 characters.

func WithTransactionType

func WithTransactionType(transactionType string) FieldValidator

WithTransactionType verifies that transactionType is exactly one character, and not the default empty value.

Jump to

Keyboard shortcuts

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