Skip to content

Commit

Permalink
Improved handling for nominet whois result
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed Jun 13, 2017
1 parent 2f5d075 commit 7d1e161
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion whois.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/zonedb/zonedb"
)

func ConvertRecord(result string) map[string]string {
func splitRecord(result string) map[string]string {
res := make(map[string]string)
r := regexp.MustCompile(`(?mi:^\s?([\w\s\/]*)\:(.*)$)`)
vars := r.FindAllStringSubmatch(result, -1)
Expand All @@ -26,6 +26,41 @@ func ConvertRecord(result string) map[string]string {
return res
}

func ConvertRecord(result string) map[string]string {
res := splitRecord(result)
r := regexp.MustCompile(`(?ms)^ +([^:]+):(\n|\r\n)(.+?)(\n|\r\n)(\n|\r\n)`)
vars := r.FindAllStringSubmatch(result, -1)
for _, vals := range vars {
resKey := ""
resVal := ""
for key, val := range vals {
if key == 1 {
resKey = val
} else if key == 3 {
tmpVal := regexp.MustCompile(`(?m)^\s*`).ReplaceAllString(val, "")

partsVal := splitRecord(tmpVal)
if len(partsVal) > 0 {
for subK, subV := range partsVal {
res[subK] = subV
}
resVal = ""
} else {
resVal = tmpVal
}
}
}

resKey = strings.TrimSpace(strings.Trim(strings.Replace(resKey, "\n", "", -1), ":"))
resVal = strings.TrimSpace(resVal)
if len(resKey) > 2 && strings.Count(resKey, " ") < 5 && len(resVal) > 0 {
res[resKey] = resVal
}

}
return res
}

func IsAvailable(domain string) (bool, error) {
result, err := GetRecord(domain)
if err != nil {
Expand Down

0 comments on commit 7d1e161

Please sign in to comment.