-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.go
59 lines (52 loc) · 1.02 KB
/
parser.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Package whois provides simple whois protocol (rfc3912) implementation.
package whois
import (
"strings"
"time"
)
// Reply contains fields from WHOIS server response.
type Reply struct {
Domain string
Organisation string
Person string
Created string
Paid time.Time
Source string
}
// GetReply returns WhoisReply for domain.
func GetReply(domain string) (Reply, error) {
var (
out string
err error
r Reply
)
out, err = QueryAll(domain)
if err != nil {
return r, err
}
buffer := strings.Split(out, "\n")
for _, line := range buffer {
field := strings.SplitN(line, ":", 2)
if len(field) == 1 {
continue
}
value := strings.TrimSpace(field[1])
switch field[0] {
case "domain":
r.Domain = value
case "organisation":
r.Organisation = value
case "person":
r.Person = value
case "created":
r.Created = value
case "paid":
r.Paid, _ = time.Parse(time.RFC3339, value)
case "source":
r.Source = value
default:
continue
}
}
return r, nil
}