Coder Social home page Coder Social logo

go-email-validator / go-email-validator Goto Github PK

View Code? Open in Web Editor NEW
51.0 5.0 11.0 539 KB

๐Ÿ“ง Golang Email address validator

License: MIT License

Go 98.98% Makefile 0.80% Dockerfile 0.22%
email email-validation email-verification email-verifier email-validator smtp-validator mail validation golang go

go-email-validator's Introduction

Go Reference codecov Go Report

Library under development (Interfaces may be changed slightly)

Demo on rapidapi.com

Install

go get -u github.com/go-email-validator/go-email-validator

Available validators

[email protected]

Usage

With builder

package main

import (
  "fmt"
  "github.com/go-email-validator/go-email-validator/pkg/ev"
  "github.com/go-email-validator/go-email-validator/pkg/ev/evmail"
)

func main() {
  // create defaults DepValidator with GetDefaultFactories() as list of validators
  builder := ev.NewDepBuilder(nil).Build()
  /*
     to set another list of initial validators
     builder := NewDepBuilder(&ValidatorMap{
         ev.ValidatorName: ev.Validator,
     }).Build()
  */

  // builder.Set(ev.ValidatorName, NewValidator()) builder
  // builder.Has(names ...ev.ValidatorName) bool
  // builder.Delete(names ...ev.ValidatorName) bool

  validator := builder.Build()

  v := validator.Validate(NewInput(evmail.FromString("[email protected]")))
  if !v.IsValid() {
    panic("email is invalid")
  }

  fmt.Println(v)
}

Single validator

package main

import (
  "fmt"
  "github.com/go-email-validator/go-email-validator/pkg/ev"
  "github.com/go-email-validator/go-email-validator/pkg/ev/evmail"
)

func main() {
  var v = ev.NewSyntaxValidator().Validate(ev.NewInput(evmail.FromString("[email protected]"))) // ev.ValidationResult

  if !v.IsValid() {
    panic("email is invalid")
  }

  fmt.Println(v)
}

Addition options

To set options for different validators, use NewInput(..., NewKVOption(ValidatorName, Options))

NewInput(
	evmail.FromString("[email protected]"), 
	NewKVOption(SMTPValidatorName, evsmtp.NewOptions(evsmtp.OptionsDTO{
		Port: 465,
    })),
)

Use function New...(...) to create structure instead of public.

How to extend

To add own validator, just implement ev.Validator interface. For validator without dependencies, you can use structure ev.AValidatorWithoutDeps

Decorators

  1. WarningsDecorator allows moving errors to warnings and change result of IsValid() in ValidationResult.
  2. Cache based on evcahce.Interface, default realization is done for gocache.

Notice, to use msgpack you should have exported fields or implement custom encoding/decoding (doc)

Logger

Package use zap.

To use logging see in log package. Default level is zap.ErrorLevel.

Addition

  1. For running workflow locally use act

FAQ

Most Internet Service Providers block outgoing SMTP request.

The StackOverflow thread could be helpful.

To check smtp in telnet

telnet

OPEN gmail-smtp-in.l.google.com 25
EHLO localhost
MAIL FROM: <[email protected]>
rcpt to: <[email protected]>
quit

Some mail providers could put your ip in spam filter.

For example:

  1. hotmail.com

Roadmap

  • Tests
    • Add functional tests
    • Find way to compare functions in tests
  • Add binary release
  • Check in spamhaus
  • Add misspelled email
  • Add DKIM checking
  • Add linter in pre-hook and ci
  • Do full thread safe library
  • Copy features from truemail

Inspired by

go-email-validator's People

Contributors

9glenda avatar dependabot[bot] avatar maranqz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

go-email-validator's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.