Send marshals an any into json and POSTs it to a URL.
(body io.Reader)
| 175 | |
| 176 | // Send marshals an any into json and POSTs it to a URL. |
| 177 | func (w *WebhookConfig) Send(body io.Reader) ([]byte, error) { |
| 178 | if w.URL == "" { |
| 179 | return nil, ErrWebhookNoURL |
| 180 | } |
| 181 | |
| 182 | w.Lock() |
| 183 | defer w.Unlock() |
| 184 | |
| 185 | w.posts++ |
| 186 | |
| 187 | ctx, cancel := context.WithTimeout(context.Background(), w.Timeout.Duration+time.Second) |
| 188 | defer cancel() |
| 189 | |
| 190 | resp, err := w.send(ctx, body) |
| 191 | if err != nil { |
| 192 | w.fails++ |
| 193 | } |
| 194 | |
| 195 | return resp, err |
| 196 | } |
| 197 | |
| 198 | func (w *WebhookConfig) send(ctx context.Context, body io.Reader) ([]byte, error) { |
| 199 | req, err := http.NewRequestWithContext(ctx, http.MethodPost, w.URL, body) |
no test coverage detected