-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
61 lines (55 loc) · 901 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
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"bufio"
"fmt"
"net/url"
"os"
)
type host struct {
http bool
https bool
hostname string
}
func main() {
var hosts = make(map[string]host)
sc := bufio.NewScanner(os.Stdin)
for sc.Scan() {
u, err := url.Parse(sc.Text())
if err != nil {
continue
}
var h host
h.hostname = u.Host
if hostInSlice(h.hostname, hosts) {
h = hosts[h.hostname]
}
if u.Scheme == "https" {
h.https = true
}
if u.Scheme == "http" {
h.http = true
}
hosts[h.hostname] = h
}
for _, hh := range hosts {
fmt.Println(buildResult(hh))
}
}
func hostInSlice(h string, hosts map[string]host) bool {
for _, hh := range hosts {
if hh.hostname == h {
return true
}
}
return false
}
func buildResult(h host) string {
var u url.URL
u.Host = h.hostname
if h.https == true {
u.Scheme = "https"
} else {
u.Scheme = "http"
}
return u.String()
}