(req *http.Request, outputObj interface{}, verbose bool)
| 113 | } |
| 114 | |
| 115 | func doRequest(req *http.Request, outputObj interface{}, verbose bool) (*http.Response, error) { |
| 116 | apiUrl := req.Header.Get("X-PromptAPIUrl") |
| 117 | if verbose { |
| 118 | log.Printf("[wcloud] sending request %s %v\n", req.Method, req.URL) |
| 119 | } |
| 120 | resp, err := http.DefaultClient.Do(req) |
| 121 | if err != nil { |
| 122 | return nil, fmt.Errorf("error contacting wcloud %q service: %v", apiUrl, err) |
| 123 | } |
| 124 | defer resp.Body.Close() |
| 125 | bodyBytes, err := io.ReadAll(resp.Body) |
| 126 | if err != nil { |
| 127 | return resp, fmt.Errorf("error reading %q response body: %v", apiUrl, err) |
| 128 | } |
| 129 | if resp.StatusCode != http.StatusOK { |
| 130 | return resp, fmt.Errorf("error contacting wcloud %q service: %s", apiUrl, resp.Status) |
| 131 | } |
| 132 | if outputObj != nil && resp.Header.Get("Content-Type") == "application/json" { |
| 133 | err = json.Unmarshal(bodyBytes, outputObj) |
| 134 | if err != nil { |
| 135 | return resp, fmt.Errorf("error decoding json: %v", err) |
| 136 | } |
| 137 | } |
| 138 | return resp, nil |
| 139 | } |
| 140 | |
| 141 | type TEventsInputType struct { |
| 142 | ClientId string `json:"clientid"` |
no test coverage detected