summaryrefslogtreecommitdiff
path: root/cmd/httpclient/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/httpclient/main.go')
-rw-r--r--cmd/httpclient/main.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/cmd/httpclient/main.go b/cmd/httpclient/main.go
new file mode 100644
index 0000000..945ee36
--- /dev/null
+++ b/cmd/httpclient/main.go
@@ -0,0 +1,50 @@
+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)
+ }
+
+ fmt.Println(links)
+}