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

Method Respond

micro/request.go:104–118  ·  view source on GitHub ↗

Respond sends the response for the request. Additional headers can be passed using [WithHeaders] option.

(response []byte, opts ...RespondOpt)

Source from the content-addressed store, hash-verified

102// Respond sends the response for the request.
103// Additional headers can be passed using [WithHeaders] option.
104func (r *request) Respond(response []byte, opts ...RespondOpt) error {
105 respMsg := &nats.Msg{
106 Data: response,
107 }
108 for _, opt := range opts {
109 opt(respMsg)
110 }
111
112 if err := r.msg.RespondMsg(respMsg); err != nil {
113 r.respondError = fmt.Errorf("%w: %s", ErrRespond, err)
114 return r.respondError
115 }
116
117 return nil
118}
119
120// RespondJSON marshals the given response value and responds to the request.
121// Additional headers can be passed using [WithHeaders] option.

Callers 1

RespondJSONMethod · 0.95

Calls 2

RespondMsgMethod · 0.80
ErrorfMethod · 0.80

Tested by

no test coverage detected