summary refs log tree commit diff stats
path: root/pkg/request
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-03-19 00:13:54 +0530
committerAndinus <andinus@nand.sh>2020-03-19 00:13:54 +0530
commit50900c5e18bd5aa1a2329ca3d53ca3713ec5d137 (patch)
treec009a73adf2225b56b654f8ea20ceb9fc6d836e0 /pkg/request
parente96878ff2d111c91feaf4308240902795b911253 (diff)
downloadcetus-50900c5e18bd5aa1a2329ca3d53ca3713ec5d137.tar.gz
Remove package cetus
Moved req.go to request package & version to main.go
Diffstat (limited to 'pkg/request')
-rw-r--r--pkg/request/req.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/pkg/request/req.go b/pkg/request/req.go
new file mode 100644
index 0000000..350f5f6
--- /dev/null
+++ b/pkg/request/req.go
@@ -0,0 +1,44 @@
+package request
+
+import (
+	"fmt"
+	"io/ioutil"
+	"net/http"
+	"time"
+)
+
+// GetRes returns api response
+func GetRes(api string, params map[string]string) (string, error) {
+	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 "", err
+	}
+
+	q := req.URL.Query()
+	for k, v := range params {
+		q.Add(k, v)
+	}
+	req.URL.RawQuery = q.Encode()
+
+	res, err := c.Do(req)
+	if err != nil {
+		return "", err
+	}
+	defer res.Body.Close()
+
+	if res.StatusCode != 200 {
+		return "", 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 "", err
+	}
+	return string(body), err
+}
c@akkartik.com> 2018-12-29 15:27:18 -0800 4890 - new html renderings' href='/akkartik/mu/commit/html/subx/039debug.cc.html?h=main&id=ac07e589b3e912c704c2011d543f18b16712ff15'>ac07e589 ^
db8a9ab5 ^
ac07e589 ^
ce2c1efc ^
e92fa89e ^
104e521c ^















ce2c1efc ^
104e521c ^















c8a3ccbe ^
104e521c ^
52daf072 ^

c504ca56 ^

52daf072 ^


c504ca56 ^


52daf072 ^
c504ca56 ^
52daf072 ^


c504ca56 ^
























fcc161e7 ^



c504ca56 ^

fcc161e7 ^
c504ca56 ^


fcc161e7 ^
c504ca56 ^

fcc161e7 ^
c504ca56 ^

fcc161e7 ^
c504ca56 ^



fcc161e7 ^
c504ca56 ^

















fcc161e7 ^
c504ca56 ^





fcc161e7 ^

c504ca56 ^

fcc161e7 ^
c504ca56 ^






fcc161e7 ^

c504ca56 ^

fcc161e7 ^
c504ca56 ^

fcc161e7 ^
c504ca56 ^
52daf072 ^
c504ca56 ^







































104e521c ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213