Skip to content

Commit

Permalink
add get, put and post method
Browse files Browse the repository at this point in the history
Signed-off-by: obaydullahmhs <[email protected]>
  • Loading branch information
obaydullahmhs committed Jan 12, 2024
1 parent be3111d commit b344d59
Show file tree
Hide file tree
Showing 42 changed files with 3,562 additions and 296 deletions.
64 changes: 58 additions & 6 deletions kafka/connect/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ type Config struct {

type Response struct {
Code int
header http.Header
body io.ReadCloser
Header http.Header
Body io.ReadCloser
}

type ResponseBody struct {
Expand All @@ -61,8 +61,60 @@ func (cc *Client) GetConnectClusterStatus() (*Response, error) {
}
response := &Response{
Code: res.StatusCode(),
header: res.Header(),
body: res.RawBody(),
Header: res.Header(),
Body: res.RawBody(),
}

return response, nil
}

func (cc *Client) GetConnector() (*Response, error) {
return cc.GetConnectClusterStatus()
}

func (cc *Client) DeleteConnector() (*Response, error) {
req := cc.Client.R().SetDoNotParseResponse(true)
res, err := req.Delete(cc.Config.api)
if err != nil {
klog.Error(err, "Failed to send http request")
return nil, err
}
response := &Response{
Code: res.StatusCode(),
Header: res.Header(),
Body: res.RawBody(),
}

return response, nil
}

func (cc *Client) PutConnector(jsonBody []byte) (*Response, error) {
req := cc.Client.R().SetDoNotParseResponse(true).SetHeader("Content-Type", "application/json").SetBody(jsonBody)
res, err := req.Put(cc.Config.api)
if err != nil {
klog.Error(err, "Failed to send http request")
return nil, err
}
response := &Response{
Code: res.StatusCode(),
Header: res.Header(),
Body: res.RawBody(),
}

return response, nil
}

func (cc *Client) PostConnector(jsonBody []byte) (*Response, error) {
req := cc.Client.R().SetDoNotParseResponse(true).SetHeader("Content-Type", "application/json").SetBody(jsonBody)
res, err := req.Post(cc.Config.api)
if err != nil {
klog.Error(err, "Failed to send http request")
return nil, err
}
response := &Response{
Code: res.StatusCode(),
Header: res.Header(),
Body: res.RawBody(),
}

return response, nil
Expand All @@ -80,10 +132,10 @@ func (cc *Client) IsConnectClusterActive(response *Response) (bool, error) {
}
return
}
}(response.body)
}(response.Body)

var responseBody ResponseBody
body, _ := io.ReadAll(response.body)
body, _ := io.ReadAll(response.Body)
err := json.Unmarshal(body, &responseBody)
if err != nil {
return false, errors.Wrap(err, "Failed to parse response body")
Expand Down
59 changes: 59 additions & 0 deletions vendor/github.com/go-logr/logr/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

168 changes: 168 additions & 0 deletions vendor/github.com/go-logr/logr/slogr/sloghandler.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b344d59

Please sign in to comment.