-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8419d07
commit 5cb6719
Showing
5 changed files
with
72 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package gtag | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/ThreeDotsLabs/watermill/message" | ||
"github.com/foomo/sesamy-go/pkg/encoding/gtag" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func MessageHandler(handler func(payload *gtag.Payload, msg *message.Message) error) func(msg *message.Message) ([]*message.Message, error) { | ||
return func(msg *message.Message) ([]*message.Message, error) { | ||
var payload *gtag.Payload | ||
|
||
// unmarshal payload | ||
if err := json.Unmarshal(msg.Payload, &payload); err != nil { | ||
return nil, errors.Wrap(err, "failed to unmarshal payload") | ||
} | ||
|
||
// handle payload | ||
if err := handler(payload, msg); err != nil { | ||
return nil, err | ||
} | ||
|
||
// marshal payload | ||
b, err := json.Marshal(payload) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to marshal payload") | ||
} | ||
msg.Payload = b | ||
|
||
return []*message.Message{msg}, nil | ||
} | ||
} |
30 changes: 0 additions & 30 deletions
30
integration/watermill/measurementprotocol/v2/eventhandler.go
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package mpv2 | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/ThreeDotsLabs/watermill/message" | ||
"github.com/foomo/sesamy-go/pkg/encoding/mpv2" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func MessageHandler(handler func(payload *mpv2.Payload[any], msg *message.Message) error) func(msg *message.Message) ([]*message.Message, error) { | ||
return func(msg *message.Message) ([]*message.Message, error) { | ||
var payload *mpv2.Payload[any] | ||
|
||
// unmarshal payload | ||
if err := json.Unmarshal(msg.Payload, &payload); err != nil { | ||
return nil, errors.Wrap(err, "failed to unmarshal payload") | ||
} | ||
|
||
// handle payload | ||
if err := handler(payload, msg); err != nil { | ||
return nil, err | ||
} | ||
|
||
// marshal payload | ||
b, err := json.Marshal(payload) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to marshal payload") | ||
} | ||
msg.Payload = b | ||
|
||
return []*message.Message{msg}, nil | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters