MCPcopy
hub / github.com/mudler/LocalAI / putRequestJSON

Function putRequestJSON

core/http/app_test.go:211–244  ·  view source on GitHub ↗
(url string, bodyJson *B)

Source from the content-addressed store, hash-verified

209}
210
211func putRequestJSON[B any](url string, bodyJson *B) error {
212 payload, err := json.Marshal(bodyJson)
213 if err != nil {
214 return err
215 }
216
217 GinkgoWriter.Printf("PUT %s: %s\n", url, string(payload))
218
219 req, err := http.NewRequest("PUT", url, bytes.NewBuffer(payload))
220 if err != nil {
221 return err
222 }
223
224 req.Header.Set("Content-Type", "application/json")
225 req.Header.Set("Authorization", bearerKey)
226
227 client := &http.Client{}
228 resp, err := client.Do(req)
229 if err != nil {
230 return err
231 }
232 defer resp.Body.Close()
233
234 body, err := io.ReadAll(resp.Body)
235 if err != nil {
236 return err
237 }
238
239 if resp.StatusCode < 200 || resp.StatusCode >= 400 {
240 return fmt.Errorf("unexpected status code: %d, body: %s", resp.StatusCode, string(body))
241 }
242
243 return nil
244}
245
246func postInvalidRequest(url string) (error, int) {
247

Callers 1

app_test.goFile · 0.85

Calls 2

SetMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected