Last active
June 9, 2022 08:08
-
-
Save thechelsuk/ff6b3fa419d525d61a6014258445c403 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # read api end point | |
| func doRequest(url string) ([]byte, error) { | |
| resp, err := http.Get(url) | |
| if err != nil { | |
| return nil, err | |
| } | |
| defer resp.Body.Close() | |
| return ioutil.ReadAll(resp.Body) | |
| } | |
| # parse api response as json | |
| func parseResponse(body []byte) ([]byte, error) { | |
| var response map[string]interface{} | |
| if err := json.Unmarshal(body, &response); err != nil { | |
| return nil, err | |
| } | |
| return json.Marshal(response) | |
| } | |
| # print json response to stdout for debugging | |
| func printResponse(body []byte) { | |
| fmt.Println(string(body)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment