emailx

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2019 License: MIT Imports: 5 Imported by: 0

README

emailx

Golang pkg for email validation and normalization.

GoDoc Travis

Email validation

  • Simple email format check (not a complicated regexp, this is why)
  • Resolve the host name
import "github.com/goware/emailx"

func main() {
    err := emailx.Validate("My+Email@wrong.example.com")
    if err != nil {
        fmt.Println("Email is not valid.")

        if err == emailx.ErrInvalidFormat {
            fmt.Println("Wrong format.")
        }

        if err == emailx.ErrUnresolvableHost {
            fmt.Println("Unresolvable host.")
        }
    }
}

Email normalization

import "github.com/goware/emailx"

func main() {
    fmt.Print(emailx.Normalize(" My+Email@example.com. "))
    // Prints my+email@example.com
}

License

Emailx is licensed under the MIT License.

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidFormat error
	ErrInvalidFormat = errors.New("invalid format")
	// ErrUnresolvableHost error
	ErrUnresolvableHost = errors.New("unresolvable host")
)

Functions

func Normalize

func Normalize(email string) string

Normalize normalizes email address.

Example
fmt.Println(Normalize(" Email+Me@example.com. "))
Output:
email+me@example.com

func Validate

func Validate(email string) (err error)

Validate checks format of a given email and resolves its host name.

Example
err := Validate("My+Email@wrong.example.com")
if err != nil {
	fmt.Println("Email is not valid.")

	if err == ErrInvalidFormat {
		fmt.Println("Wrong format.")
	}

	if err == ErrUnresolvableHost {
		fmt.Println("Unresolvable host.")
	}
}
Output:
Email is not valid.
Unresolvable host.

func ValidateFast

func ValidateFast(email string) (err error)

ValidateFast checks format of a given email.

func ValidateWithContext

func ValidateWithContext(ctx context.Context, email string) (err error)

ValidateWithContext checks format of a given email and resolves its host name. Context can be used for cancellation

Types

This section is empty.

Jump to

Keyboard shortcuts

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