MCPcopy
hub / github.com/nats-io/nats.go / RespondJSON

Method RespondJSON

micro/request.go:122–128  ·  view source on GitHub ↗

RespondJSON marshals the given response value and responds to the request. Additional headers can be passed using [WithHeaders] option.

(response any, opts ...RespondOpt)

Source from the content-addressed store, hash-verified

120// RespondJSON marshals the given response value and responds to the request.
121// Additional headers can be passed using [WithHeaders] option.
122func (r *request) RespondJSON(response any, opts ...RespondOpt) error {
123 resp, err := json.Marshal(response)
124 if err != nil {
125 return ErrMarshalResponse
126 }
127 return r.Respond(resp, opts...)
128}
129
130// Error prepares and publishes error response from a handler.
131// A response error should be set containing an error code and description.

Callers

nothing calls this directly

Calls 1

RespondMethod · 0.95

Tested by

no test coverage detected