From 8a3554d4f32d631bd1c7cc6254ab11b14b541c67 Mon Sep 17 00:00:00 2001 From: demo Date: Fri, 8 May 2026 10:19:23 -0400 Subject: feat: separate into remote and local commands I'd like to be able to read HTML locally as well. --- cmd/httpclient/main.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 cmd/httpclient/main.go (limited to 'cmd/httpclient') 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) +} -- cgit v1.2.3