validator

package module
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: LGPL-3.0 Imports: 10 Imported by: 1

README

validator

Library that validates different things:

  • A/CNAME/MX lookups
  • Domain names
  • Emails
  • etc

Check go doc for examples

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSpamlist = fmt.Errorf("spamlist")
	ErrNoMX     = fmt.Errorf("no MX")
	ErrSMTP     = fmt.Errorf("SMTP")
	ErrSPF      = fmt.Errorf("SPF")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Email  Email                         // Email config
	Domain Domain                        // Domain config
	Log    func(msg string, args ...any) // Log func
}

Config of the validator

type Domain

type Domain struct {
	// Enforce enforces domain check and rejects empty domains
	Enforce bool
	// PrivateSuffixes considers subdomains with the following suffixes as domains
	PrivateSuffixes []string
}

Domain checks configuration

type Email

type Email struct {
	// Enforce enforces email check and rejects empty emails
	Enforce bool
	// SMTP enforces SMTP check (email actually exists on mail server) and rejects non-existing emails
	SMTP bool
	// SPF enforces SPF record check (sender allowed to use that email and send emails) and rejects unathorized emails
	SPF bool
	// MX enforces MX records check on email's mail server
	MX bool
	// From is a valid email address that will be used for SMTP checks
	From string
	// Spamlist is a list of spam emails with wildcards
	Spamlist []string
	// contains filtered or unexported fields
}

Email checks configuration

type V

type V struct {
	// contains filtered or unexported fields
}

V is a validator implementation

func New

func New(cfg *Config) *V

New validator

func (*V) A

func (v *V) A(host string) bool

A checks if host has at least one A record

func (*V) CNAME

func (v *V) CNAME(host string) bool

CNAME checks if host has at least one CNAME record

func (*V) Domain

func (v *V) Domain(domain string) bool

Domain checks if domain is valid

func (*V) DomainString

func (v *V) DomainString(domain string) bool

DomainString checks if domain string / value is valid using string checks like length and regexp

func (*V) Email

func (v *V) Email(email string, optionalSenderIP ...net.IP) bool

Email checks if email is valid

func (*V) GetBase

func (v *V) GetBase(domain string) string

GetBase returns base domain/host of the provided domain

func (*V) MX

func (v *V) MX(host string) bool

MX checks if host has at least one MX record

func (*V) NS added in v2.1.0

func (v *V) NS(host string, contains ...string) bool

NS checks if host has at least one NS record, and optionally checks if the NS record contains the given string

Jump to

Keyboard shortcuts

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