-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.go
49 lines (43 loc) · 859 Bytes
/
data.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
package whois
import (
"bufio"
"bytes"
"embed"
)
var (
//go:embed .whois.list .non-icann.whois.list
_whoisList embed.FS
whoisServerData = make(map[string][]string)
)
func init() {
parseData(".whois.list", ".non-icann.whois.list")
}
func parseData(filenames ...string) {
for _, filename := range filenames {
file, err := _whoisList.Open(filename)
if err != nil {
panic(err)
}
br := bufio.NewReader(file)
for {
var line []byte
if line, _, err = br.ReadLine(); err != nil {
break
}
arr := bytes.Split(line, []byte(" "))
if len(arr) < 2 {
continue
}
server := make([]string, len(arr)-1)
for i := 1; i < len(arr); i++ {
if len(arr[i]) > 3 {
server = append(server, string(arr[i]))
}
}
if len(arr) > 0 {
whoisServerData[string(arr[0])] = server
}
}
_ = file.Close()
}
}