Skip to content

Commit 636626c

Browse files
authored
feat: support native rest api response (#487)
* feat: support native rest api response * feat: support native rest api response * test: support native rest api response * chore: bump version
1 parent 546aeea commit 636626c

File tree

3 files changed

+712
-2
lines changed

3 files changed

+712
-2
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v1.4.10
1+
VERSION=v1.4.11
22

33
ifndef GOBIN
44
ifndef GOPATH

pkg/client/client.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ func (c *CfClient) RestAPI(ctx context.Context, opt *RequestOptions) ([]byte, er
106106
return nil, err
107107
}
108108

109+
res, err = c.wrapResponse(res)
110+
if err != nil {
111+
return nil, err
112+
}
113+
109114
defer res.Body.Close()
110115
bytes, err := io.ReadAll(res.Body)
111116
if err != nil {
@@ -114,6 +119,9 @@ func (c *CfClient) RestAPI(ctx context.Context, opt *RequestOptions) ([]byte, er
114119

115120
return bytes, nil
116121
}
122+
func (c *CfClient) NativeRestAPI(ctx context.Context, opt *RequestOptions) (*http.Response, error) {
123+
return c.apiCall(ctx, c.baseUrl, opt)
124+
}
117125

118126
func (c *CfClient) GraphqlAPI(ctx context.Context, query string, variables any, result any) error {
119127
body := map[string]any{
@@ -128,6 +136,11 @@ func (c *CfClient) GraphqlAPI(ctx context.Context, query string, variables any,
128136
return err
129137
}
130138

139+
res, err = c.wrapResponse(res)
140+
if err != nil {
141+
return err
142+
}
143+
131144
defer res.Body.Close()
132145
bytes, err := io.ReadAll(res.Body)
133146
if err != nil {
@@ -175,6 +188,10 @@ func (c *CfClient) apiCall(ctx context.Context, baseUrl *url.URL, opt *RequestOp
175188
return nil, fmt.Errorf("failed to send request: %w", err)
176189
}
177190

191+
return res, nil
192+
}
193+
194+
func (c *CfClient) wrapResponse(res *http.Response) (*http.Response, error) {
178195
if res.StatusCode >= http.StatusBadRequest {
179196
defer res.Body.Close()
180197
bytes, err := io.ReadAll(res.Body)
@@ -189,7 +206,6 @@ func (c *CfClient) apiCall(ctx context.Context, baseUrl *url.URL, opt *RequestOp
189206
body: body,
190207
}
191208
}
192-
193209
return res, nil
194210
}
195211

0 commit comments

Comments
 (0)