1 package nats 2 3 import ( 4 "context" 5 6 "github.com/nats-io/nats.go" 7 ) 8 9 // DecodeRequestFunc extracts a user-domain request object from a publisher 10 // request object. It's designed to be used in NATS subscribers, for subscriber-side 11 // endpoints. One straightforward DecodeRequestFunc could be something that 12 // JSON decodes from the request body to the concrete response type. 13 type DecodeRequestFunc func(context.Context, *nats.Msg) (request interface{}, err error) 14 15 // EncodeRequestFunc encodes the passed request object into the NATS request 16 // object. It's designed to be used in NATS publishers, for publisher-side 17 // endpoints. One straightforward EncodeRequestFunc could something that JSON 18 // encodes the object directly to the request payload. 19 type EncodeRequestFunc func(context.Context, *nats.Msg, interface{}) error 20 21 // EncodeResponseFunc encodes the passed response object to the subscriber reply. 22 // It's designed to be used in NATS subscribers, for subscriber-side 23 // endpoints. One straightforward EncodeResponseFunc could be something that 24 // JSON encodes the object directly to the response body. 25 type EncodeResponseFunc func(context.Context, string, *nats.Conn, interface{}) error 26 27 // DecodeResponseFunc extracts a user-domain response object from an NATS 28 // response object. It's designed to be used in NATS publisher, for publisher-side 29 // endpoints. One straightforward DecodeResponseFunc could be something that 30 // JSON decodes from the response payload to the concrete response type. 31 type DecodeResponseFunc func(context.Context, *nats.Msg) (response interface{}, err error) 32 33