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

Function makeAnonPostReq

pkg/wcloud/wcloud.go:90–113  ·  view source on GitHub ↗
(ctx context.Context, apiUrl string, data interface{})

Source from the content-addressed store, hash-verified

88}
89
90func makeAnonPostReq(ctx context.Context, apiUrl string, data interface{}) (*http.Request, error) {
91 endpoint := GetEndpoint()
92 if endpoint == "" {
93 return nil, errors.New("wcloud endpoint not set")
94 }
95 var dataReader io.Reader
96 if data != nil {
97 byteArr, err := json.Marshal(data)
98 if err != nil {
99 return nil, fmt.Errorf("error marshaling json for %s request: %v", apiUrl, err)
100 }
101 dataReader = bytes.NewReader(byteArr)
102 }
103 fullUrl := GetEndpoint() + apiUrl
104 req, err := http.NewRequestWithContext(ctx, "POST", fullUrl, dataReader)
105 if err != nil {
106 return nil, fmt.Errorf("error creating %s request: %v", apiUrl, err)
107 }
108 req.Header.Set("Content-Type", "application/json")
109 req.Header.Set("X-PromptAPIVersion", strconv.Itoa(APIVersion))
110 req.Header.Set("X-PromptAPIUrl", apiUrl)
111 req.Close = true
112 return req, nil
113}
114
115func doRequest(req *http.Request, outputObj interface{}, verbose bool) (*http.Response, error) {
116 apiUrl := req.Header.Get("X-PromptAPIUrl")

Callers 3

sendTEventsBatchFunction · 0.85
sendTelemetryFunction · 0.85
SendNoTelemetryUpdateFunction · 0.85

Calls 2

GetEndpointFunction · 0.85
SetMethod · 0.45

Tested by

no test coverage detected