Skip to content

Commit

Permalink
fix: nats publisher func to encode req
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushkedia29 committed Mar 27, 2024
1 parent fe6d078 commit d3abde0
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions transport/nats/publisher_fn.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ package nats
import (
"context"
"encoding/json"

"github.com/nats-io/nats.go"
natn "github.com/nats-io/nats.go"
)

// EncodeJSONRequest is an Encoder that serializes the request as a
// JSON object to the Data of the Msg. Many JSON-over-NATS services can use it as
// a sensible default.
func EncodeJSONRequest(_ context.Context, msg *natn.Msg, request interface{}) error {
func EncodeJSONRequest(_ context.Context, msg *natn.Msg, request interface{}) (*nats.Msg, error) {
b, err := json.Marshal(request)
if err != nil {
return err
return nil, err
}

msg.Data = b

return nil
return msg, nil
}

0 comments on commit d3abde0

Please sign in to comment.