Only create payload struct once.

(But keep making bytes.Buffer multiple times as these is read from by each http request)
This commit is contained in:
Michael Kaye 2022-02-01 13:59:01 +00:00
parent 4e3eeec92c
commit 095b55e640

View file

@ -521,14 +521,14 @@ func (s *submitServer) submitGenericWebhook(p parsedPayload, listingURL string,
if s.genericWebhookClient == nil {
return nil
}
genericHookPayload := genericWebhookPayload{
parsedPayload: p,
ReportURL: reportURL,
ListingURL: listingURL,
}
for _, url := range s.cfg.GenericWebhookURLs {
// Enrich the parsedPayload with a reportURL and listingURL, to convert a single struct
// to JSON easily
genericHookPayload := genericWebhookPayload{
parsedPayload: p,
ReportURL: reportURL,
ListingURL: listingURL,
}
payloadBuffer := new(bytes.Buffer)
json.NewEncoder(payloadBuffer).Encode(genericHookPayload)