MCPcopy
hub / github.com/wavetermdev/waveterm / doRequest

Function doRequest

pkg/wcloud/wcloud.go:115–139  ·  view source on GitHub ↗
(req *http.Request, outputObj interface{}, verbose bool)

Source from the content-addressed store, hash-verified

113}
114
115func 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
141type TEventsInputType struct {
142 ClientId string `json:"clientid"`

Callers 4

sendTEventsBatchFunction · 0.85
sendTelemetryFunction · 0.85
SendNoTelemetryUpdateFunction · 0.85
SendDiagnosticPingFunction · 0.85

Calls 3

CloseMethod · 0.65
GetMethod · 0.45
ReadAllMethod · 0.45

Tested by

no test coverage detected