mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-22 13:50:49 +01:00
Fix/optimize isTempError method
Not that this particular part of the code is performance critical, but I figured that the `strconv.Atoi()` is actually useless in here. Since all we want to know is if the error code from the SMTP server is a 4xx error, we can just check the first rune of the returned error. The `Atoi` provides us with no advantage over the simple rune compare (except of taking about 3ns longer to execute)
This commit is contained in:
parent
43efd6b3a8
commit
15b3a0028a
1 changed files with 1 additions and 9 deletions
10
senderror.go
10
senderror.go
|
@ -7,7 +7,6 @@ package mail
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -132,12 +131,5 @@ func (r SendErrReason) String() string {
|
||||||
// isTempError checks the given SMTP error and returns true if the given error is of temporary nature
|
// isTempError checks the given SMTP error and returns true if the given error is of temporary nature
|
||||||
// and should be retried
|
// and should be retried
|
||||||
func isTempError(e error) bool {
|
func isTempError(e error) bool {
|
||||||
ec, err := strconv.Atoi(e.Error()[:3])
|
return e.Error()[0] == '4'
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if ec >= 400 && ec <= 500 {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue