-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (37 loc) · 904 Bytes
/
main.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 main
import (
"bufio"
"fmt"
"os"
"strings"
"net/url"
"github.com/sirupsen/logrus"
"golang.org/x/net/publicsuffix"
)
func main() {
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
inputURL := scanner.Text()
if inputURL == "" {
continue
}
if !strings.HasPrefix(inputURL, "http://") && !strings.HasPrefix(inputURL, "https://") {
inputURL = "https://" + inputURL
}
parsedURL, err := url.Parse(inputURL)
if err != nil {
logrus.Warnf("failed to parse URL %s: %v", inputURL, err)
}
host := parsedURL.Hostname()
apexDomain, err := publicsuffix.EffectiveTLDPlusOne(host)
if err != nil {
logrus.Warnf("failed to get apex domain for %s: %v", host, err)
}
lowerApexDomain := strings.ToLower(apexDomain)
fmt.Println(lowerApexDomain)
}
if err := scanner.Err(); err != nil {
logrus.Error("error reading input: ", err)
panic(err)
}
}