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

Method apiRequest

jetstream/api.go:127–151  ·  view source on GitHub ↗

a RequestWithContext with tracing via TraceCB

(ctx context.Context, subj string, data ...[]byte)

Source from the content-addressed store, hash-verified

125
126// a RequestWithContext with tracing via TraceCB
127func (js *jetStream) apiRequest(ctx context.Context, subj string, data ...[]byte) (*jetStreamMsg, error) {
128 subj = js.apiSubject(subj)
129 var req []byte
130 if len(data) > 0 {
131 req = data[0]
132 }
133 if js.opts.ClientTrace != nil {
134 ctrace := js.opts.ClientTrace
135 if ctrace.RequestSent != nil {
136 ctrace.RequestSent(subj, req)
137 }
138 }
139 resp, err := js.conn.RequestWithContext(ctx, subj, req)
140 if err != nil {
141 return nil, err
142 }
143 if js.opts.ClientTrace != nil {
144 ctrace := js.opts.ClientTrace
145 if ctrace.ResponseReceived != nil {
146 ctrace.ResponseReceived(subj, resp.Data, resp.Header)
147 }
148 }
149
150 return js.toJSMsg(resp), nil
151}
152
153func (js *jetStream) apiSubject(subj string) string {
154 if js.opts.apiPrefix == "" {

Callers 2

apiRequestJSONMethod · 0.95
getMsgMethod · 0.80

Calls 3

apiSubjectMethod · 0.95
toJSMsgMethod · 0.95
RequestWithContextMethod · 0.45

Tested by

no test coverage detected