summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/httpclient/main.go50
-rw-r--r--cmd/localclient/main.go14
2 files changed, 64 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)
+}
diff --git a/cmd/localclient/main.go b/cmd/localclient/main.go
new file mode 100644
index 0000000..21d405d
--- /dev/null
+++ b/cmd/localclient/main.go
@@ -0,0 +1,14 @@
+package main
+
+import (
+ "flag"
+ "log"
+)
+
+func main() {
+ filename := flag.String("file", "", "Local HTML file")
+ if *filename == "" {
+ log.Fatal("Missing -file argument")
+ }
+
+}