Skip to content

Commit

Permalink
adjust ip error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
luludotdev committed Jun 3, 2021
1 parent 1916d50 commit 5880787
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
5 changes: 1 addition & 4 deletions autodns/pkg/iptools/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"io/ioutil"
"net/http"
"strconv"
"strings"
"time"

"github.com/lolPants/autodns/autodns/pkg/logger"
Expand Down Expand Up @@ -35,9 +34,7 @@ func getAddress(subdomain string) <-chan *result {

if err != nil {
logger.Stderr.Printf(1, "failed to resolve IP"+subdomain+" address, error: `%s`\n", err.Error())
if strings.Contains(err.Error(), "no such host") == false {
res.Error = err
}
res.Error = err

r <- res
return
Expand Down
15 changes: 6 additions & 9 deletions autodns/pkg/iptools/iptools.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package iptools

import (
"errors"
)

// Result represents the result of an IP Lookup
type Result struct {
Error error
Expand All @@ -19,15 +23,8 @@ func Lookup() <-chan *Result {
v4task, v6task := getAddress("v4"), getAddress("v6")
v4ptr, v6ptr := <-v4task, <-v6task

if v4ptr.Error != nil {
res.Error = v4ptr.Error
r <- res

return
}

if v6ptr.Error != nil {
res.Error = v6ptr.Error
if v4ptr.Data == nil && v6ptr.Data == nil {
res.Error = errors.New("both IPv4 and IPv6 cannot be found")
r <- res

return
Expand Down

0 comments on commit 5880787

Please sign in to comment.