There was an error while loading. Please reload this page.
1 parent 8012815 commit 157a7cdCopy full SHA for 157a7cd
wrapper.go
@@ -0,0 +1,42 @@
1
+package request
2
+
3
+import (
4
+"encoding/json"
5
+"io"
6
+"net/http"
7
+)
8
9
+func ToObject[T any](resp *http.Response, err error) (*T, error) {
10
+if err != nil {
11
+return nil, err
12
+}
13
14
+defer resp.Body.Close()
15
16
+out := new(T)
17
18
+contentType := resp.Header.Get("Content-Type")
19
+switch contentType {
20
+case "application/json":
21
+if err := json.NewDecoder(resp.Body).Decode(&out); err != nil {
22
23
24
25
26
+return out, nil
27
28
29
+func ToString(resp *http.Response, err error) (string, error) {
30
31
+return "", err
32
33
34
+data, err := io.ReadAll(resp.Body)
35
36
37
38
39
+resp.Body.Close()
40
41
+return string(data), nil
42
0 commit comments