Skip to content

Commit 064b5f5

Browse files
committed
flag introduced
1 parent aebe5d3 commit 064b5f5

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

client/events/EventClient.go

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
type EventClientConfig struct {
4141
DestinationURL string `env:"EVENT_URL" envDefault:"http://localhost:3000/notify" description:"Notifier service url"`
4242
NotificationMedium NotificationMedium `env:"NOTIFICATION_MEDIUM" envDefault:"rest" description:"notification medium"`
43+
EnableNotifierV2 bool `env:"ENABLE_NOTIFIER_V2" envDefault:"false" description:"enable notifier v2"`
4344
}
4445
type NotificationMedium string
4546

@@ -259,21 +260,34 @@ func (impl *EventRESTClientImpl) sendEventsOnNats(body []byte) error {
259260
// do not call this method if notification module is not installed
260261
func (impl *EventRESTClientImpl) sendEvent(event Event) (bool, error) {
261262
impl.logger.Debugw("event before send", "event", event)
262-
body, err := json.Marshal(event)
263-
if err != nil {
264-
impl.logger.Errorw("error while marshaling event request ", "err", err)
265-
return false, err
266-
}
267-
if impl.config.NotificationMedium == PUB_SUB {
268-
err = impl.sendEventsOnNats(body)
263+
var body string
264+
var destinationUrl string
265+
if impl.config.EnableNotifierV2 {
266+
// logic to get NotificationSettings from event
267+
268+
// embed event and NotificationSettings in body
269+
270+
// destination Url
271+
destinationUrl = impl.config.DestinationURL + "/v2"
272+
} else {
273+
destinationUrl = impl.config.DestinationURL
274+
body, err := json.Marshal(event)
269275
if err != nil {
270-
impl.logger.Errorw("error while publishing event ", "err", err)
276+
impl.logger.Errorw("error while marshaling event request ", "err", err)
271277
return false, err
272278
}
273-
return true, nil
279+
if impl.config.NotificationMedium == PUB_SUB {
280+
err = impl.sendEventsOnNats(body)
281+
if err != nil {
282+
impl.logger.Errorw("error while publishing event ", "err", err)
283+
return false, err
284+
}
285+
return true, nil
286+
}
274287
}
288+
275289
var reqBody = []byte(body)
276-
req, err := http.NewRequest(http.MethodPost, impl.config.DestinationURL, bytes.NewBuffer(reqBody))
290+
req, err := http.NewRequest(http.MethodPost, destinationUrl, bytes.NewBuffer(reqBody))
277291
if err != nil {
278292
impl.logger.Errorw("error while writing event", "err", err)
279293
return false, err

0 commit comments

Comments
 (0)