validator

package
v0.0.0-...-3306650 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrValidation = errors.New("validation_failed")

ErrValidation is returned when validation fails.

Functions

func ValidateEmail

func ValidateEmail(s string) error

Email is a validator that checks if the value is a valid email address.

func ValidateSolanaWalletAddr

func ValidateSolanaWalletAddr(addr string) error

ValidateSolanaWalletAddr validates a Solana wallet address. Returns an error if the address is invalid, nil otherwise.

func ValidateStruct

func ValidateStruct(s interface{}) url.Values

ValidateStruct validate struct data - s: struct pointer - return: validation errors as url.Values or nil if no errors

Types

type EmailAddress

type EmailAddress struct {
	// LocalPart usually the username of an email address.
	LocalPart string

	// Domain is the part of the email address after the last @.
	// This should be DNS resolvable to an email server.
	Domain string
}

EmailAddress is a structure that stores the address local-part@domain parts.

func (EmailAddress) String

func (e EmailAddress) String() string

func (EmailAddress) ValidateHost

func (e EmailAddress) ValidateHost() error

ValidateHost will test if the email address is actually reachable. It will first try to resolve the host and then start a mail transaction.

func (EmailAddress) ValidateIcanSuffix

func (e EmailAddress) ValidateIcanSuffix() error

ValidateIcanSuffix will test if the public suffix of the domain is managed by ICANN using the golang.org/x/net/publicsuffix package. If not it will return an error. Note that if this method returns an error it does not necessarily mean that the email address is invalid. Also the suffix list in the standard package is embedded and thereby not up to date.

type ValidationError

type ValidationError struct {
	Err    error      // The underlying error.
	Values url.Values // A map of field names to error messages.
}

ValidationError is a custom error type that contains a map of field names to error messages.

func NewValidationError

func NewValidationError(values url.Values) *ValidationError

NewValidationError returns a new ValidationError.

func (*ValidationError) AddValue

func (e *ValidationError) AddValue(key, message string) *ValidationError

AddValue adds a new error message to the map.

func (*ValidationError) AddValues

func (e *ValidationError) AddValues(values url.Values) *ValidationError

AddValues adds a new error message to the map.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Error returns the error message.

func (*ValidationError) Unwrap

func (e *ValidationError) Unwrap() error

Unwrap returns the underlying error.

Jump to

Keyboard shortcuts

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