summaryrefslogtreecommitdiff
path: root/internal/links/fetch.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/links/fetch.go')
-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
+}