@@ -267,18 +267,19 @@ func (impl *EventRESTClientImpl) sendEvent(event Event) (bool, error) {
267
267
impl .logger .Debugw ("event before send" , "event" , event )
268
268
269
269
// Step 1: Create payload and destination URL based on config
270
- body , destinationUrl , err := impl .createPayloadAndDestination (event )
270
+ bodyBytes , destinationUrl , err := impl .createPayloadAndDestination (event )
271
271
if err != nil {
272
272
return false , err
273
273
}
274
274
275
275
// Step 2: Send via appropriate medium (NATS or REST)
276
- return impl .deliverEvent (body , destinationUrl )
276
+ return impl .deliverEvent (bodyBytes , destinationUrl )
277
277
}
278
278
279
- func (impl * EventRESTClientImpl ) createPayloadAndDestination (event Event ) (string , string , error ) {
280
- var body string
279
+ func (impl * EventRESTClientImpl ) createPayloadAndDestination (event Event ) ([] byte , string , error ) {
280
+ var bodyBytes [] byte
281
281
var destinationUrl string
282
+ var err error
282
283
283
284
if impl .config .EnableNotifierV2 {
284
285
// V2 payload and URL
@@ -302,7 +303,7 @@ func (impl *EventRESTClientImpl) createPayloadAndDestination(event Event) (strin
302
303
)
303
304
if err != nil {
304
305
impl .logger .Errorw ("error while fetching notification settings" , "err" , err )
305
- return "" , "" , err
306
+ return nil , "" , err
306
307
}
307
308
308
309
notificationSettingsBean := make ([]* repository.NotificationSettingsBean , 0 )
@@ -311,7 +312,7 @@ func (impl *EventRESTClientImpl) createPayloadAndDestination(event Event) (strin
311
312
if item .Config != "" {
312
313
if err := json .Unmarshal ([]byte (item .Config ), & config ); err != nil {
313
314
impl .logger .Errorw ("error while unmarshaling config" , "err" , err )
314
- return "" , "" , err
315
+ return nil , "" , err
315
316
}
316
317
}
317
318
notificationSettingsBean = append (notificationSettingsBean , & repository.NotificationSettingsBean {
@@ -332,30 +333,28 @@ func (impl *EventRESTClientImpl) createPayloadAndDestination(event Event) (strin
332
333
"notificationSettings" : notificationSettingsBean ,
333
334
}
334
335
335
- bodyBytes , err : = json .Marshal (combinedPayload )
336
+ bodyBytes , err = json .Marshal (combinedPayload )
336
337
if err != nil {
337
338
impl .logger .Errorw ("error while marshaling combined event request" , "err" , err )
338
- return "" , "" , err
339
+ return nil , "" , err
339
340
}
340
- body = string (bodyBytes )
341
341
} else {
342
342
// Default payload and URL
343
343
destinationUrl = impl .config .DestinationURL
344
- bodyBytes , err : = json .Marshal (event )
344
+ bodyBytes , err = json .Marshal (event )
345
345
if err != nil {
346
346
impl .logger .Errorw ("error while marshaling event request" , "err" , err )
347
- return "" , "" , err
347
+ return nil , "" , err
348
348
}
349
- body = string (bodyBytes )
350
349
}
351
350
352
- return body , destinationUrl , nil
351
+ return bodyBytes , destinationUrl , nil
353
352
}
354
353
355
- func (impl * EventRESTClientImpl ) deliverEvent (body string , destinationUrl string ) (bool , error ) {
354
+ func (impl * EventRESTClientImpl ) deliverEvent (bodyBytes [] byte , destinationUrl string ) (bool , error ) {
356
355
// Check if it should use NATS
357
356
if impl .config .NotificationMedium == PUB_SUB {
358
- err := impl .sendEventsOnNats ([] byte ( body ) )
357
+ err := impl .sendEventsOnNats (bodyBytes )
359
358
if err != nil {
360
359
impl .logger .Errorw ("error while publishing event" , "err" , err )
361
360
return false , err
@@ -364,8 +363,7 @@ func (impl *EventRESTClientImpl) deliverEvent(body string, destinationUrl string
364
363
}
365
364
366
365
// Default to REST
367
- reqBody := []byte (body )
368
- req , err := http .NewRequest (http .MethodPost , destinationUrl , bytes .NewBuffer (reqBody ))
366
+ req , err := http .NewRequest (http .MethodPost , destinationUrl , bytes .NewBuffer (bodyBytes ))
369
367
if err != nil {
370
368
impl .logger .Errorw ("error while writing event" , "err" , err )
371
369
return false , err
0 commit comments