summary refs log tree commit diff stats
path: root/fetch/request.go
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-03-22 13:43:54 +0530
committerAndinus <andinus@nand.sh>2020-03-22 13:43:54 +0530
commit9fde6e5a892b228c2d64af05b02380847573c832 (patch)
tree0d8fb21a7825b0e9f678180f5b66d866c8b38afa /fetch/request.go
parentc3ff3d068fdeacacec1f693bf9513742983814ad (diff)
downloadindus-9fde6e5a892b228c2d64af05b02380847573c832.tar.gz
Add initial version
Diffstat (limited to 'fetch/request.go')
-rw-r--r--fetch/request.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/fetch/request.go b/fetch/request.go
new file mode 100644
index 0000000..a3c6f23
--- /dev/null
+++ b/fetch/request.go
@@ -0,0 +1,41 @@
+package fetch
+
+import (
+	"fmt"
+	"io/ioutil"
+	"net/http"
+	"time"
+)
+
+func getRes(api string) ([]byte, error) {
+	var body []byte
+
+	c := http.Client{
+		// TODO: timeout should be configurable by the user
+		Timeout: time.Second * 64,
+	}
+
+	req, err := http.NewRequest(http.MethodGet, api, nil)
+	if err != nil {
+		return body, err
+	}
+
+	req.Header.Set("User-Agent", "Andinus / Indus - framagit.org/andinus/indus")
+
+	res, err := c.Do(req)
+	if err != nil {
+		return body, err
+	}
+	defer res.Body.Close()
+
+	if res.StatusCode != 200 {
+		return body, fmt.Errorf("Unexpected response status code received: %d %s",
+			res.StatusCode, http.StatusText(res.StatusCode))
+	}
+
+	body, err = ioutil.ReadAll(res.Body)
+	if err != nil {
+		return body, err
+	}
+	return body, err
+}