diff options
| author | demo <demo@antix1> | 2026-05-10 11:05:59 -0400 |
|---|---|---|
| committer | demo <demo@antix1> | 2026-05-10 11:05:59 -0400 |
| commit | 6ba67c878cefe8123e3fcd81f5dd181920a22c08 (patch) | |
| tree | b13416ba1bbc720f4415a7fa4f553c21b2bdb50c /internal | |
| parent | 6957934261ae4abdf4905263b15037ac243f6c7b (diff) | |
feat: write fetch function
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/links/fetch.go | 28 |
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 +} |
