A bit of refactoring
lucio81 opened this issue · comments
Hi, there is a specific reason to duplicate the code in the 2 validation function? The Validate function does exactly what the FastValidation does plus the MX lookup. My 2 cents for the Validate function:
func Validate(email string) error {
fastValidationErr := ValidateFast(email)
if fastValidationErr != nil {
return fastValidationErr
}
at := strings.LastIndex(email, "@")
host := email[at+1:]
switch host {
case "localhost", "example.com":
return nil
}
if _, err := net.LookupMX(host); err != nil {
if _, err := net.LookupIP(host); err != nil {
// Only fail if both MX and A records are missing - any of the
// two is enough for an email to be deliverable
return ErrUnresolvableHost
}
}
return nil
}
Actually I think you could completely separate the SyntaxValidate from the DomainValidate. In case both of those are called.
Thanks
@lucio81 I think you're right. Mind sending a PR to improve this pkg?