( url string, pld any, headers map[string]string, username, password string, )
| 75 | } |
| 76 | |
| 77 | func newHTTPRequest( |
| 78 | url string, pld any, headers map[string]string, username, password string, |
| 79 | ) (*http.Request, error) { |
| 80 | buf := &bytes.Buffer{} |
| 81 | if err := json.NewEncoder(buf).Encode(pld); err != nil { |
| 82 | return nil, err |
| 83 | } |
| 84 | req, err := http.NewRequest(http.MethodPost, url, buf) |
| 85 | if err != nil { |
| 86 | return nil, err |
| 87 | } |
| 88 | req.Header.Set("Content-Type", "application/json") |
| 89 | for k, v := range headers { |
| 90 | req.Header.Set(k, v) |
| 91 | } |
| 92 | if username != "" { |
| 93 | req.SetBasicAuth(username, password) |
| 94 | } |
| 95 | return req, nil |
| 96 | } |
| 97 | |
| 98 | func httpExchange( |
| 99 | ctx context.Context, httpReq *http.Request, res any, do func(*http.Request) (*http.Response, error), |
no test coverage detected