MCPcopy Create free account
hub / github.com/Unpackerr/unpackerr / Send

Method Send

pkg/unpackerr/webhook.go:177–196  ·  view source on GitHub ↗

Send marshals an any into json and POSTs it to a URL.

(body io.Reader)

Source from the content-addressed store, hash-verified

175
176// Send marshals an any into json and POSTs it to a URL.
177func (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
198func (w *WebhookConfig) send(ctx context.Context, body io.Reader) ([]byte, error) {
199 req, err := http.NewRequestWithContext(ctx, http.MethodPost, w.URL, body)

Callers 1

sendWebhookWithLogMethod · 0.80

Calls 1

sendMethod · 0.95

Tested by

no test coverage detected