Skip to content

Commit

Permalink
fix: add DoGetBytesRaw(). (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsluoyz authored Mar 26, 2022
1 parent 3d40821 commit 6c02fdf
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions auth/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ func DoGetBytes(url string) ([]byte, error) {
}
}(resp.Body)

respByte, err := ioutil.ReadAll(resp.Body)
respBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}

var response Response
err = json.Unmarshal(respByte, &response)
err = json.Unmarshal(respBytes, &response)
if err != nil {
return nil, err
}
Expand All @@ -76,6 +76,36 @@ func DoGetBytes(url string) ([]byte, error) {
return res, nil
}

// DoGetBytesRaw is a general function to get response from param url through HTTP Get method.
func DoGetBytesRaw(url string) ([]byte, error) {
client := &http.Client{}

req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}

req.SetBasicAuth(authConfig.ClientId, authConfig.ClientSecret)

resp, err := client.Do(req)
if err != nil {
return nil, err
}
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
return
}
}(resp.Body)

respBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}

return respBytes, nil
}

func doPost(action string, queryMap map[string]string, postBytes []byte, isFile bool) (*Response, error) {
client := &http.Client{}
url := GetUrl(action, queryMap)
Expand Down

0 comments on commit 6c02fdf

Please sign in to comment.