| 221 | } |
| 222 | |
| 223 | func (s *Sender) createHTTPRequest(ctx context.Context, body []byte) (*http.Request, error) { |
| 224 | apiURL := fmt.Sprintf("%s/v1/notifytargetsync", s.baseURL) |
| 225 | req, err := http.NewRequestWithContext(ctx, http.MethodPost, apiURL, bytes.NewBuffer(body)) |
| 226 | if err != nil { |
| 227 | return nil, fmt.Errorf("%w: failed to create HTTP request: %w", ErrPermanentSystem, err) |
| 228 | } |
| 229 | |
| 230 | token, err := s.tokenSource.Token() |
| 231 | if err != nil { |
| 232 | return nil, fmt.Errorf("%w: failed to retrieve access token: %w", ErrPermanentSystem, err) |
| 233 | } |
| 234 | req.Header.Set("Authorization", "Bearer "+token.AccessToken) |
| 235 | req.Header.Set("Content-Type", "application/json") |
| 236 | |
| 237 | return req, nil |
| 238 | } |
| 239 | |
| 240 | func (s *Sender) executeRequest(req *http.Request) (*http.Response, []byte, error) { |
| 241 | resp, err := s.httpClient.Do(req) |