GetJSON gets a json response from url
(url string, obj interface{}, client *http.Client)
| 93 | |
| 94 | // GetJSON gets a json response from url |
| 95 | func GetJSON(url string, obj interface{}, client *http.Client) (*http.Response, error) { |
| 96 | if client == nil { |
| 97 | client, _ = CreateHTTPClient("") |
| 98 | } |
| 99 | |
| 100 | resp, err := client.Get(url) |
| 101 | if err != nil { |
| 102 | return resp, err |
| 103 | } |
| 104 | if resp.StatusCode != http.StatusOK { |
| 105 | return resp, errors.New("HTTP status code is not 200") |
| 106 | } |
| 107 | defer resp.Body.Close() |
| 108 | body, err := io.ReadAll(resp.Body) |
| 109 | if err != nil { |
| 110 | return resp, err |
| 111 | } |
| 112 | return resp, json.Unmarshal(body, obj) |
| 113 | } |
| 114 | |
| 115 | // FindAllSubmatchInFile calls re.FindAllSubmatch to find matches in given file |
| 116 | func FindAllSubmatchInFile(fileName string, re *regexp.Regexp) (matches [][][]byte, err error) { |