-
Notifications
You must be signed in to change notification settings - Fork 6
/
print.go
93 lines (80 loc) · 2.62 KB
/
print.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package fasttld
import (
"github.com/fatih/color"
)
// PrintRes pretty-prints URL components from ExtractResult
func PrintRes(url string, res ExtractResult) {
var leftAttrsFilled = []color.Attribute{color.FgHiYellow, color.Bold}
var leftAttrsBlank = []color.Attribute{color.FgHiBlack}
var rightAttrs = []color.Attribute{color.FgHiWhite}
if len(url) != 0 {
color.New(leftAttrsFilled...).Print(" url: ")
} else {
color.New(leftAttrsBlank...).Print(" url: ")
}
color.New(rightAttrs...).Println(url)
if len(res.Scheme) != 0 {
color.New(leftAttrsFilled...).Print(" scheme: ")
} else {
color.New(leftAttrsBlank...).Print(" scheme: ")
}
color.New(rightAttrs...).Println(res.Scheme)
if len(res.UserInfo) != 0 {
color.New(leftAttrsFilled...).Print(" userinfo: ")
} else {
color.New(leftAttrsBlank...).Print(" userinfo: ")
}
color.New(rightAttrs...).Println(res.UserInfo)
if len(res.SubDomain) != 0 {
color.New(leftAttrsFilled...).Print(" subdomain: ")
} else {
color.New(leftAttrsBlank...).Print(" subdomain: ")
}
color.New(rightAttrs...).Println(res.SubDomain)
if len(res.Domain) != 0 {
color.New(leftAttrsFilled...).Print(" domain: ")
} else {
color.New(leftAttrsBlank...).Print(" domain: ")
}
color.New(rightAttrs...).Println(res.Domain)
if len(res.Suffix) != 0 {
color.New(leftAttrsFilled...).Print(" suffix: ")
} else {
color.New(leftAttrsBlank...).Print(" suffix: ")
}
color.New(rightAttrs...).Println(res.Suffix)
if len(res.RegisteredDomain) != 0 {
color.New(leftAttrsFilled...).Print("registered domain: ")
} else {
color.New(leftAttrsBlank...).Print("registered domain: ")
}
color.New(rightAttrs...).Println(res.RegisteredDomain)
if len(res.Port) != 0 {
color.New(leftAttrsFilled...).Print(" port: ")
} else {
color.New(leftAttrsBlank...).Print(" port: ")
}
color.New(rightAttrs...).Println(res.Port)
if len(res.Path) != 0 {
color.New(leftAttrsFilled...).Print(" path: ")
} else {
color.New(leftAttrsBlank...).Print(" path: ")
}
color.New(rightAttrs...).Println(res.Path)
if res.HostType != 0 {
color.New(color.FgHiBlue, color.Bold).Print(" host type: ")
} else {
color.New(leftAttrsBlank...).Print(" host type: ")
}
switch res.HostType {
case HostName:
color.New(rightAttrs...).Println("hostname")
case IPv4:
color.New(rightAttrs...).Println("ipv4 address")
case IPv6:
color.New(rightAttrs...).Println("ipv6 address")
default:
color.New(rightAttrs...).Println()
}
color.New().Println()
}