You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[NATS transport] Support for headers in EncodeJSONResponse #1238
Since release v1.11.0, nats.go supports message headers. headers are very useful to transfer metadata together with messages.
I'm proposing to add basic support for headers in the default response encoder.
Proposed API
The idea is to do something similar it's done for transport/http with the Headerer interface. API change proposal is backward compatible (no public API change)
typeHeadererinterface {
Headers() Header
}
funcEncodeJSONResponse(_ context.Context, replystring, nc*nats.Conn, responseinterface{}) error {
msg:=nats.NewMessage(reply)
ifnc. HeadersSupported() {
ifheaderer, ok:=response.(Headerer); ok {
msg.Header=headerer.Headers() // I wrote that to make it shorter
}
}
msg.Data, err:=json.Marshal(response)
iferr!=nil {
returnerr
}
returnnc.PublishMsg(msg)
}
No, I'm wondering if a default implementation could have the same feature
than the HTTP one.
==============
Massimo Costa
Il mer 29 giu 2022, 18:51 Peter Bourgon ***@***.***> ha
scritto:
So I'd like to try to avoid the situation where default implementations provided by Go kit, like this function, being continuously updated with new features/capabilities of their underlying systems. I see that as unsustainable, as well as unnecessary: Go kit is designed specifically to allow consumers to provide their own EncodeJSONResponse functions.
Can you suggest some wording for the docs that would make this clear?
Go kit provides default implementation for many functions (for instance http.EncodeJSONResponse, nats.EncodeJSONResponse, http.DefaultErrorEncoder, nats.DefaultErrorEncoder,...) but is designed to allow consumers to provide their implementation (maybe to use the latest features of the underlying systems).
Activity
peterbourgon commentedon Jun 29, 2022
EncodeJSONResponse is a default implementation of a function that consumers can also provide themselves. Does anything prevent that, here?
mcosta74 commentedon Jun 29, 2022
peterbourgon commentedon Jul 3, 2022
So I'd like to try to avoid the situation where default implementations provided by Go kit, like this function, being continuously updated with new features/capabilities of their underlying systems. I see that as unsustainable, as well as unnecessary: Go kit is designed specifically to allow consumers to provide their own EncodeJSONResponse functions.
Can you suggest some wording for the docs that would make this clear?
mcosta74 commentedon Oct 18, 2022
Something like
?
peterbourgon commentedon May 11, 2023
SGTM
mcosta74 commentedon May 17, 2023
Can you suggest "where" to put this sentence in the documentation?
?