summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordemo <demo@antix1>2026-05-10 11:05:59 -0400
committerdemo <demo@antix1>2026-05-10 11:05:59 -0400
commit6ba67c878cefe8123e3fcd81f5dd181920a22c08 (patch)
treeb13416ba1bbc720f4415a7fa4f553c21b2bdb50c
parent6957934261ae4abdf4905263b15037ac243f6c7b (diff)
feat: write fetch function
-rw-r--r--internal/links/fetch.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/internal/links/fetch.go b/internal/links/fetch.go
new file mode 100644
index 0000000..864d754
--- /dev/null
+++ b/internal/links/fetch.go
@@ -0,0 +1,28 @@
+package links
+
+import (
+ "bufio"
+ "fmt"
+ "io"
+ "net/http"
+ "time"
+)
+
+func fetch(rawURL string, timeoutSecs int) (io.Reader, error) {
+ client := http.Client{
+ Timeout: time.Duration(timeoutSecs) * time.Second,
+ }
+
+ req, err := http.NewRequest(http.MethodGet, rawURL, nil)
+ if err != nil {
+ return nil, fmt.Errorf("can't create %s request for %s", http.MethodGet, rawURL)
+ }
+
+ resp, err := client.Do(req)
+ if err != nil {
+ return nil, fmt.Errorf("client failed to perform %s request for %s", http.MethodGet, rawURL)
+ }
+ defer resp.Body.Close()
+
+ return bufio.NewReader(resp.Body), nil
+}