Respond sends the response for the request. Additional headers can be passed using [WithHeaders] option.
(response []byte, opts ...RespondOpt)
| 102 | // Respond sends the response for the request. |
| 103 | // Additional headers can be passed using [WithHeaders] option. |
| 104 | func (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. |
no test coverage detected