ev

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2023 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// GravatarValidatorName is name for validation by https://www.gravatar.com/
	GravatarValidatorName ValidatorName = "Gravatar"
	// GravatarURL is url for gravatar validation
	GravatarURL string = "https://www.gravatar.com/avatar/%x?d=404"
	// DefaultGravatarTimeout is default timeout for gravatar connection
	DefaultGravatarTimeout = 5 * time.Second
)
View Source
const BanWordsUsernameErr = "BanWordsUsernameError"

BanWordsUsernameErr is text for BanWordsUsernameError.Error

View Source
const BlackListEmailsErr = "BlackListEmailsError"

BlackListEmailsErr is text for BlackListEmailsError.Error

View Source
const DisposableErr = "DisposableError"

DisposableErr is text for DisposableError.Error

View Source
const FreeErr = "FreeError"

FreeErr is text for FreeError.Error

View Source
const GravatarErr = "GravatarError"

GravatarErr is text for GravatarError.Error

View Source
const RoleErr = "RoleError"

RoleErr is text for RoleError.Error

View Source
const SyntaxErr = "SyntaxErr"

SyntaxErr is text for SyntaxError.Error

View Source
const WhiteListErr = "WhiteListError"

WhiteListErr is text for WhiteListError.Error

Variables

View Source
var DefaultEmailRegex = regexp.MustCompile("(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])")
View Source
var EmptyDeps = make([]ValidatorName, 0)

Functions

func DefaultGetMD5Hash

func DefaultGetMD5Hash(str string) []byte

DefaultGetMD5Hash is a default implementation of GetMD5Hash

func DomainCacheKeyGetter

func DomainCacheKeyGetter(input Input, _ ...ValidationResult) interface{}

DomainCacheKeyGetter generates key as domain

func EmailCacheKeyGetter

func EmailCacheKeyGetter(input Input, _ ...ValidationResult) interface{}

EmailCacheKeyGetter generates key as full email

func NewDepsError

func NewDepsError() error

NewDepsError creates DepsError

Types

type AValidationResult

type AValidationResult struct {
	IsValidVal  bool
	ErrorsVal   []error
	WarningsVal []error
	NameVal     ValidatorName
}

AValidationResult is abstract class for extending of validation

func (*AValidationResult) DecodeMsgpack

func (a *AValidationResult) DecodeMsgpack(dec *msgpack.Decoder) error

DecodeMsgpack is used to fix this problem https://github.com/vmihailenco/msgpack/issues/294

func (*AValidationResult) EncodeMsgpack

func (a *AValidationResult) EncodeMsgpack(enc *msgpack.Encoder) error

EncodeMsgpack is used to fix this problem https://github.com/vmihailenco/msgpack/issues/294

func (*AValidationResult) Errors

func (a *AValidationResult) Errors() []error

Errors of result after validation

func (*AValidationResult) HasErrors

func (a *AValidationResult) HasErrors() bool

HasErrors checks for the presence of the Errors

func (*AValidationResult) HasWarnings

func (a *AValidationResult) HasWarnings() bool

HasWarnings checks for the presence of the Warnings

func (*AValidationResult) IsValid

func (a *AValidationResult) IsValid() bool

IsValid is status of validation

func (*AValidationResult) SetErrors

func (a *AValidationResult) SetErrors(errors []error)

SetErrors sets errors

func (*AValidationResult) SetWarnings

func (a *AValidationResult) SetWarnings(warnings []error)

SetWarnings sets warnings

func (*AValidationResult) ValidatorName

func (a *AValidationResult) ValidatorName() ValidatorName

ValidatorName returns name of validator

func (*AValidationResult) Warnings

func (a *AValidationResult) Warnings() []error

Warnings of result after validation

type AValidatorWithoutDeps

type AValidatorWithoutDeps struct{}

AValidatorWithoutDeps is an abstract structure for validator without dependencies

func (AValidatorWithoutDeps) GetDeps

func (a AValidatorWithoutDeps) GetDeps() []ValidatorName

GetDeps returns dependencies of Validator

type BanWordsUsernameError

type BanWordsUsernameError struct{}

BanWordsUsernameError is BanWordsUsernameValidatorName error

func (BanWordsUsernameError) Error

func (BanWordsUsernameError) Error() string

type BlackListDomainsError

type BlackListDomainsError struct{}

BlackListDomainsError is BlackListEmailsValidatorName error

func (BlackListDomainsError) Error

func (BlackListDomainsError) Error() string

type BlackListEmailsError

type BlackListEmailsError struct{}

BlackListEmailsError is BlackListEmailsValidatorName error

func (BlackListEmailsError) Error

func (BlackListEmailsError) Error() string

type CacheDecorator

type CacheDecorator struct {
	Validator Validator
	Cache     evcache.Interface
	GetKey    CacheKeyGetter
}

func (*CacheDecorator) GetDeps

func (c *CacheDecorator) GetDeps() []ValidatorName

func (*CacheDecorator) Validate

func (c *CacheDecorator) Validate(input Input, results ...ValidationResult) (result ValidationResult)

type CacheKeyGetter

type CacheKeyGetter func(input Input, results ...ValidationResult) interface{}

CacheKeyGetter is type for key generators To use complex keys you can use https://github.com/vmihailenco/msgpack/

type ChangeableValidationResult

type ChangeableValidationResult interface {
	SetErrors([]error)
	SetWarnings([]error)
}

ChangeableValidationResult is ValidationResult with changeable errors and warnings

type DepBuilder

type DepBuilder struct {
	Validators ValidatorMap
}

DepBuilder is used to form Validator

func NewDepBuilder

func NewDepBuilder(validators ValidatorMap) *DepBuilder

NewDepBuilder instantiates Validator with ValidatorMap or GetDefaultFactories validators

func (*DepBuilder) Build

func (d *DepBuilder) Build() Validator

Build builds Validator based on configuration

func (*DepBuilder) Delete

func (d *DepBuilder) Delete(names ...ValidatorName) *DepBuilder

Delete deletes validators by ValidatorName...

func (*DepBuilder) Get

func (d *DepBuilder) Get(name ValidatorName) Validator

Get returns validator by ValidatorName

func (*DepBuilder) Has

func (d *DepBuilder) Has(names ...ValidatorName) bool

Has checks for existing validators by ValidatorName...

func (*DepBuilder) Set

func (d *DepBuilder) Set(name ValidatorName, validator Validator) *DepBuilder

Set sets validator by ValidatorName

type DepResult

type DepResult map[ValidatorName]ValidationResult

DepResult is alias for results of nested validators

type DepValidationResult

type DepValidationResult interface {
	ValidationResult
	GetResults() DepResult
}

DepValidationResult is representation of DepValidatorName result

type DepValidator

type DepValidator struct {
	AValidatorWithoutDeps
	Deps ValidatorMap
}

func (DepValidator) Validate

func (d DepValidator) Validate(input Input, _ ...ValidationResult) ValidationResult

type DepsError

type DepsError struct{}

DepsError is DepValidatorName error

func (*DepsError) Error

func (*DepsError) Error() string

type DisposableError

type DisposableError struct{}

DisposableError is DisposableValidatorName error

func (DisposableError) Error

func (DisposableError) Error() string

type EmptyMXsError

type EmptyMXsError struct{}

EmptyMXsError is error of MXValidatorName

func (EmptyMXsError) Error

func (EmptyMXsError) Error() string

type FreeError

type FreeError struct{}

FreeError is FreeValidatorName error

func (FreeError) Error

func (FreeError) Error() string

type GetMD5Hash

type GetMD5Hash func(str string) []byte

GetMD5Hash is function interface, which returns md5 for string

type GravatarError

type GravatarError struct{}

GravatarError is GravatarValidatorName error

func (GravatarError) Error

func (GravatarError) Error() string

type GravatarOptions

type GravatarOptions interface {
	Timeout() time.Duration
}

GravatarOptions describes gravatar options

func DefaultGravatarOptions

func DefaultGravatarOptions() GravatarOptions

DefaultGravatarOptions returns options with default values

func NewGravatarOptions

func NewGravatarOptions(dto GravatarOptionsDTO) GravatarOptions

NewGravatarOptions instantiates GravatarOptions

type GravatarOptionsDTO

type GravatarOptionsDTO struct {
	Timeout time.Duration
}

GravatarOptionsDTO is dto for NewGravatarOptions

type GravatarValidationResult

type GravatarValidationResult interface {
	URL() string
	ValidationResult
}

GravatarValidationResult is result of GravatarValidatorName

func NewGravatarValidationResult

func NewGravatarValidationResult(url string, result *AValidationResult) GravatarValidationResult

NewGravatarValidationResult instantiates result of GravatarValidationResult

type Input

type Input interface {
	Email() evmail.Address
	Option(name ValidatorName) interface{}
}

Input consists of input data for Validator.Validate

func NewInput

func NewInput(email evmail.Address, kvOptions ...KVOption) Input

NewInput create Input from evmail.Address and KVOption list

func NewInputFromMap

func NewInputFromMap(email evmail.Address, options map[ValidatorName]interface{}) Input

NewInputFromMap create Input from evmail.Address and options

type InputStruct

type InputStruct struct {
	EmailAddress evmail.Address
	Options      map[ValidatorName]interface{}
}

func (*InputStruct) Email

func (i *InputStruct) Email() evmail.Address

func (*InputStruct) Option

func (i *InputStruct) Option(name ValidatorName) interface{}

type IsWarning

type IsWarning func(err error) bool

IsWarning is type to detect error as warning

func NewIsWarning

func NewIsWarning(warningMap WarningSet, isWarning func(warningMap WarningSet) IsWarning) IsWarning

NewIsWarning creates function for detection of warnings

type KVOption

type KVOption struct {
	Name   ValidatorName
	Option interface{}
}

KVOption needs to form options in Input

func NewKVOption

func NewKVOption(name ValidatorName, option interface{}) KVOption

NewKVOption instantiates KVOption

type MXValidationResult

type MXValidationResult interface {
	MX() evsmtp.MXs
	ValidationResult
}

MXValidationResult is result of MXValidatorName

func NewMXValidationResult

func NewMXValidationResult(mx evsmtp.MXs, result *AValidationResult) MXValidationResult

NewMXValidationResult instantiates result of MXValidatorName

type RoleError

type RoleError struct{}

RoleError is error of RoleValidatorName

func (RoleError) Error

func (RoleError) Error() string

type SyntaxError

type SyntaxError struct{}

SyntaxError is error of SyntaxValidatorName

func (SyntaxError) Error

func (SyntaxError) Error() string

type SyntaxValidatorResult

type SyntaxValidatorResult interface {
	ValidationResult
}

SyntaxValidatorResult is interface of SyntaxValidatorName result

type ValidationResult

type ValidationResult interface {
	// IsValid is status of validation
	IsValid() bool
	// Errors of result after validation
	Errors() []error
	// HasErrors checks for the presence of the Errors
	HasErrors() bool
	// Warnings of result after validation
	Warnings() []error
	// HasWarnings checks for the presence of the Warnings
	HasWarnings() bool
	// ValidatorName returns name of validator
	ValidatorName() ValidatorName
}

ValidationResult is interface to represent result of validation

func GravatarGetError

func GravatarGetError(err error) ValidationResult

func NewDepValidatorResult

func NewDepValidatorResult(isValid bool, results DepResult) ValidationResult

NewDepValidatorResult returns DepValidatorName result

func NewResult

func NewResult(isValid bool, errors []error, warnings []error, name ValidatorName) ValidationResult

NewResult returns result of validation by parameters

func NewValidResult

func NewValidResult(name ValidatorName) ValidationResult

NewValidResult returns valid validation result

func SyntaxGetError

func SyntaxGetError() ValidationResult

type ValidationResultStruct

type ValidationResultStruct = AValidationResult

type Validator

type Validator interface {
	GetDeps() []ValidatorName
	Validate(input Input, results ...ValidationResult) ValidationResult
}

Validator is interface for validators

func DefaultNewMXValidator

func DefaultNewMXValidator() Validator

DefaultNewMXValidator instantiates default MXValidatorName based on evsmtp.LookupMX

func FreeDefaultValidator

func FreeDefaultValidator() Validator

FreeDefaultValidator instantiates default FreeValidatorName based on free.NewWillWhiteSetFree()

func GetDefaultSMTPValidator

func GetDefaultSMTPValidator(dto evsmtp.CheckerDTO) Validator

GetDefaultSMTPValidator instantiates default SMTPValidatorName

func NewBanWordsUsername

func NewBanWordsUsername(inStrings contains.InStrings) Validator

NewBanWordsUsername instantiates BanWordsUsernameValidatorName validator

func NewBlackListEmailsValidator

func NewBlackListEmailsValidator(d contains.InSet) Validator

NewBlackListEmailsValidator instantiates BlackListEmailsValidatorName validator

func NewBlackListValidator

func NewBlackListValidator(d contains.InSet) Validator

NewBlackListValidator instantiates BlackListDomainsValidatorName validator

func NewCacheDecorator

func NewCacheDecorator(validator Validator, cache evcache.Interface, getKey CacheKeyGetter) Validator

NewCacheDecorator instantiates cache decorator

func NewDepValidator

func NewDepValidator(deps ValidatorMap) Validator

NewDepValidator instantiates DepValidatorName validator

func NewDisposableValidator

func NewDisposableValidator(d contains.InSet) Validator

NewDisposableValidator instantiates DisposableValidatorName

func NewFreeValidator

func NewFreeValidator(f contains.InSet) Validator

NewFreeValidator instantiates FreeValidatorName

func NewGravatarValidator

func NewGravatarValidator() Validator

NewGravatarValidator instantiates GravatarValidatorName validator with GravatarURL for validation

func NewGravatarValidatorWithURL

func NewGravatarValidatorWithURL(gravatarURL string) Validator

NewGravatarValidatorWithURL instantiates GravatarValidatorName validator

func NewMXValidator

func NewMXValidator(lookupMX evsmtp.FuncLookupMX) Validator

NewMXValidator instantiates MXValidatorName based on evsmtp.FuncLookupMX

func NewRoleValidator

func NewRoleValidator(r contains.InSet) Validator

NewRoleValidator instantiates RoleValidatorName

func NewSMTPValidator

func NewSMTPValidator(Checker evsmtp.Checker) Validator

NewSMTPValidator instantiates SMTPValidatorName

func NewSyntaxRegexValidator

func NewSyntaxRegexValidator(emailRegex *regexp.Regexp) Validator

NewSyntaxRegexValidator creates SyntaxValidatorName, based on *regexp.Regexp Example of regular expressions HTML5 - https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address Different variations - http://emailregex.com/, RFC 5322 is used as default emailRegex

func NewSyntaxValidator

func NewSyntaxValidator() Validator

NewSyntaxValidator instantiates SyntaxValidatorName based on mail.ParseAddress

func NewWarningsDecorator

func NewWarningsDecorator(validator Validator, isWarning IsWarning) Validator

NewWarningsDecorator creates warning decorator to skip some errors

func NewWhiteListValidator

func NewWhiteListValidator(d contains.InSet) Validator

NewWhiteListValidator instantiates WhiteListDomainValidatorName

type ValidatorMap

type ValidatorMap map[ValidatorName]Validator

ValidatorMap alias for map[ValidatorName]Validator

func GetDefaultFactories

func GetDefaultFactories() ValidatorMap

GetDefaultFactories returns default list ValidatorMap

type ValidatorName

type ValidatorName string

ValidatorName is type to represent validator name

const BanWordsUsernameValidatorName ValidatorName = "BanWordsUsername"

BanWordsUsernameValidatorName is name of ban words username If email username has ban worlds, the email is invalid

const BlackListDomainsValidatorName ValidatorName = "BlackListDomains"

BlackListDomainsValidatorName is name of black domain It checks an domain of email in list. If the address domain is in, the email is invalid.

const BlackListEmailsValidatorName ValidatorName = "BlackListEmails"

BlackListEmailsValidatorName is name of black list emails It checks an email in list. If the address is in, the email is invalid.

const DepValidatorName ValidatorName = "depValidator"

DepValidatorName is name of validator with dependencies

const DisposableValidatorName ValidatorName = "DisposableValidator"

DisposableValidatorName is name of disposable validator

const FreeValidatorName ValidatorName = "FreeValidator"

FreeValidatorName is name of free validator

const MXValidatorName ValidatorName = "MXValidator"

MXValidatorName is name of mx validator

const OtherValidator ValidatorName = "other"

OtherValidator is ValidatorName for unknown Validator

const RoleValidatorName ValidatorName = "RoleValidator"

RoleValidatorName is name of role validator

const SMTPValidatorName ValidatorName = "SMTPValidator"

SMTPValidatorName is name of smtp validator

const SyntaxValidatorName ValidatorName = "syntaxValidator"

SyntaxValidatorName is name of syntax validator

const WhiteListDomainValidatorName ValidatorName = "WhiteListDomain"

WhiteListDomainValidatorName name of whiteListValidator

func (ValidatorName) String

func (v ValidatorName) String() string

type WarningSet

type WarningSet sets.Set

WarningSet is alias for sets.Set

type WhiteListError

type WhiteListError struct{}

WhiteListError is error for WhiteListDomainValidatorName

func (WhiteListError) Error

func (WhiteListError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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