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 ¶
- func Validate(validators ...FieldValidator) error
- type FieldValidator
- func WithAmount(amount uint, required bool) FieldValidator
- func WithBillerClientID(billerClientID string, required bool) FieldValidator
- func WithClientIPAddress(address string) FieldValidator
- func WithCurrency(currency types.Currency) FieldValidator
- func WithDescription(description string) FieldValidator
- func WithLanguage(language types.Language) FieldValidator
- func WithPerspayeeExpiry(prespayeeExpiry string) FieldValidator
- func WithTransactionID(transactionID string) FieldValidator
- func WithTransactionType(transactionType string) FieldValidator
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.