blob: 3744d78a41e62ff60e045c4d68a047baf3e7b733 (
plain)
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
|
package main
import (
"flag"
"fmt"
"log"
"net/http"
"time"
"git.brandonirizarry.xyz/links/internal/findlinks"
)
func main() {
// Logging configuration.
log.SetFlags(log.LstdFlags | log.Lshortfile)
// CLI flag configuration.
rawURL := flag.String("url", "", "Web address of target HTML")
timeoutSecs := flag.Int("timeout", 2, "Number of seconds after which to time out")
flag.Parse()
if *rawURL == "" {
log.Fatal("Missing -url")
}
// Configure the request.
timeout := time.Duration(*timeoutSecs) * time.Second
client := http.Client{
Timeout: timeout,
}
req, err := http.NewRequest(http.MethodGet, *rawURL, nil)
if err != nil {
log.Fatal(err)
}
// Perform the request.
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
links, err := findlinks.FindLinks(resp.Body)
if err != nil {
log.Fatal(err)
}
for _, link := range links {
fmt.Printf("%s\n\n", findlinks.Format(link, "\n"))
}
}
|