MCPcopy Index your code
hub / github.com/cloudquery/cloudquery / UploadReaderWithContentType

Function UploadReaderWithContentType

cli/internal/hub/util.go:84–104  ·  view source on GitHub ↗
(ctx context.Context, uploadURL string, reader io.Reader, contentType string)

Source from the content-addressed store, hash-verified

82}
83
84func UploadReaderWithContentType(ctx context.Context, uploadURL string, reader io.Reader, contentType string) error {
85 req, err := http.NewRequestWithContext(ctx, http.MethodPut, uploadURL, reader)
86 if err != nil {
87 return fmt.Errorf("failed to create request: %w", err)
88 }
89 req.Header.Set("Content-Type", contentType)
90
91 resp, err := http.DefaultClient.Do(req)
92 if err != nil {
93 return err
94 }
95 defer resp.Body.Close()
96 if resp.StatusCode != http.StatusOK {
97 body, readErr := io.ReadAll(resp.Body)
98 if readErr != nil {
99 return fmt.Errorf("failed to read response body: %w", readErr)
100 }
101 return fmt.Errorf("status %s: %s", resp.Status, body)
102 }
103 return nil
104}
105
106func NormalizeContent(s string) string {
107 s = strings.TrimSpace(s)

Callers 1

Calls 3

ErrorfMethod · 0.80
CloseMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected