Skip to content

Commit

Permalink
Decoders use the pubsub message instead of the message payload (#5)
Browse files Browse the repository at this point in the history
* pass the pubsub message instead of data

* use msg.Data when no decoder defined, default case
  • Loading branch information
Baptiste Boussemart authored and jfbus committed Oct 4, 2018
1 parent c3083b7 commit a973122
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pubsub/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
type EndpointOption func(*Endpoint)

// DecodeRequestFunc is a function to decode pub/sub message and return structured data
type DecodeRequestFunc func(context.Context, []byte) (interface{}, error)
type DecodeRequestFunc func(context.Context, *pubsub.Message) (interface{}, error)

// Endpoint for this pubsub transport
type Endpoint struct {
Expand Down
2 changes: 1 addition & 1 deletion pubsub/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func makeReceiveFunc(e *Endpoint) func(ctx context.Context, msg *pubsub.Message)
err error
)
if e.decode != nil {
dec, err = e.decode(ctx, msg.Data)
dec, err = e.decode(ctx, msg)
} else {
dec = msg.Data
}
Expand Down
4 changes: 2 additions & 2 deletions pubsub/pubsub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ type testStruct struct {
Status int `json:"status"`
}

func decode(ctx context.Context, b []byte) (interface{}, error) {
func decode(ctx context.Context, m *pubsub.Message) (interface{}, error) {
d := &testStruct{}
err := json.Unmarshal(b, d)
err := json.Unmarshal(m.Data, d)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit a973122

Please sign in to comment.