Skip to content

Commit

Permalink
feat: marshal raw data to JSON
Browse files Browse the repository at this point in the history
Signed-off-by: Valery Piashchynski <[email protected]>
  • Loading branch information
rustatian committed Aug 7, 2022
1 parent e938443 commit 69e41d1
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions beanstalkjobs/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ func (c *Consumer) unpack(id uint64, data []byte, out *Item) error {
uid := uuid.NewString()
c.log.Debug("get raw payload", zap.String("assigned ID", uid))

if isJSONEncoded(data) != nil {
data, err = json.Marshal(data)
if err != nil {
return err
}
}

*out = Item{
Job: auto,
Ident: uid,
Expand Down Expand Up @@ -182,3 +189,8 @@ func (c *Consumer) unpack(id uint64, data []byte, out *Item) error {

return nil
}

func isJSONEncoded(data []byte) error {
var a any
return json.Unmarshal(data, &a)
}

0 comments on commit 69e41d1

Please sign in to comment.