| 1 | // Copyright 2021-2023 The NATS Authors |
| 2 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | // you may not use this file except in compliance with the License. |
| 4 | // You may obtain a copy of the License at |
| 5 | // |
| 6 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | // |
| 8 | // Unless required by applicable law or agreed to in writing, software |
| 9 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | // See the License for the specific language governing permissions and |
| 12 | // limitations under the License. |
| 13 | |
| 14 | package natsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ |
| 15 | |
| 16 | import ( |
| 17 | "contextscip-go gomod github.com/golang/go/src go1.25.0 context/" |
| 18 | "encoding/jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/" |
| 19 | "errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/" |
| 20 | "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/" |
| 21 | "strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/" |
| 22 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 23 | "timescip-go gomod github.com/golang/go/src go1.25.0 time/" |
| 24 | ) |
| 25 | |
| 26 | // JetStreamManager manages JetStream Streams and Consumers. |
| 27 | type JetStreamManagerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JetStreamManager# interface { |
| 28 | // AddStream creates a stream. |
| 29 | AddStreamscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JetStreamManager#AddStream.(cfg *StreamConfigscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) (*StreamInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo#, error) |
| 30 | |
| 31 | // UpdateStream updates a stream. |
| 32 | UpdateStreamscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JetStreamManager#UpdateStream.(cfg *StreamConfigscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) (*StreamInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo#, error) |
| 33 | |
| 34 | // DeleteStream deletes a stream. |
| 35 | DeleteStreamscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JetStreamManager#DeleteStream.(name string, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) error |
| 36 | |
| 37 | // StreamInfo retrieves information from a stream. |
| 38 | StreamInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JetStreamManager#StreamInfo.(stream string, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) (*StreamInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo#, error) |
| 39 | |
| 40 | // PurgeStream purges a stream messages. |
| 41 | PurgeStreamscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JetStreamManager#PurgeStream.(name string, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) error |
| 42 | |
| 43 | // StreamsInfo can be used to retrieve a list of StreamInfo objects. |
| 44 | // Deprecated: Use Streams() instead. |
| 45 | StreamsInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JetStreamManager#StreamsInfo.(opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) <-chan *StreamInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo# |
| 46 | |
| 47 | // Streams can be used to retrieve a list of StreamInfo objects. |
| 48 | Streamsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JetStreamManager#Streams.(opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) <-chan *StreamInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo# |
| 49 | |
| 50 | // StreamNames is used to retrieve a list of Stream names. |
| 51 | StreamNamesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JetStreamManager#StreamNames.(opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) <-chan string |
| 52 | |
| 53 | // GetMsg retrieves a raw stream message stored in JetStream by sequence number. |
| 54 | // Use options nats.DirectGet() or nats.DirectGetNext() to trigger retrieval |
| 55 | // directly from a distributed group of servers (leader and replicas). |
| 56 | // The stream must have been created/updated with the AllowDirect boolean. |
| 57 | GetMsgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JetStreamManager#GetMsg.(name string, seq uint64, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) (*RawStreamMsgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RawStreamMsg#, error) |
| 58 | |
| 59 | // GetLastMsg retrieves the last raw stream message stored in JetStream by subject. |
| 60 | // Use option nats.DirectGet() to trigger retrieval |
| 61 | // directly from a distributed group of servers (leader and replicas). |
| 62 | // The stream must have been created/updated with the AllowDirect boolean. |
| 63 | GetLastMsgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JetStreamManager#GetLastMsg.(name, subject string, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) (*RawStreamMsgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RawStreamMsg#, error) |
| 64 | |
| 65 | // DeleteMsg deletes a message from a stream. The message is marked as erased, but its value is not overwritten. |
| 66 | DeleteMsgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JetStreamManager#DeleteMsg.(name string, seq uint64, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) error |
| 67 | |
| 68 | // SecureDeleteMsg deletes a message from a stream. The deleted message is overwritten with random data |
| 69 | // As a result, this operation is slower than DeleteMsg() |
| 70 | SecureDeleteMsgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JetStreamManager#SecureDeleteMsg.(name string, seq uint64, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) error |
| 71 | |
| 72 | // AddConsumer adds a consumer to a stream. |
| 73 | // If the consumer already exists, and the configuration is the same, it |
| 74 | // will return the existing consumer. |
| 75 | // If the consumer already exists, and the configuration is different, it |
| 76 | // will return ErrConsumerNameAlreadyInUse. |
| 77 | AddConsumerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JetStreamManager#AddConsumer.(stream string, cfg *ConsumerConfigscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerConfig#, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) (*ConsumerInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerInfo#, error) |
| 78 | |
| 79 | // UpdateConsumer updates an existing consumer. |
| 80 | UpdateConsumerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JetStreamManager#UpdateConsumer.(stream string, cfg *ConsumerConfigscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerConfig#, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) (*ConsumerInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerInfo#, error) |
| 81 | |
| 82 | // DeleteConsumer deletes a consumer. |
| 83 | DeleteConsumerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JetStreamManager#DeleteConsumer.(stream, consumer string, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) error |
| 84 | |
| 85 | // ConsumerInfo retrieves information of a consumer from a stream. |
| 86 | ConsumerInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JetStreamManager#ConsumerInfo.(stream, name string, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) (*ConsumerInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerInfo#, error) |
| 87 | |
| 88 | // ConsumersInfo is used to retrieve a list of ConsumerInfo objects. |
| 89 | // Deprecated: Use Consumers() instead. |
| 90 | ConsumersInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JetStreamManager#ConsumersInfo.(stream string, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) <-chan *ConsumerInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerInfo# |
| 91 | |
| 92 | // Consumers is used to retrieve a list of ConsumerInfo objects. |
| 93 | Consumersscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JetStreamManager#Consumers.(stream string, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) <-chan *ConsumerInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerInfo# |
| 94 | |
| 95 | // ConsumerNames is used to retrieve a list of Consumer names. |
| 96 | ConsumerNamesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JetStreamManager#ConsumerNames.(stream string, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) <-chan string |
| 97 | |
| 98 | // AccountInfo retrieves info about the JetStream usage from an account. |
| 99 | AccountInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JetStreamManager#AccountInfo.(opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) (*AccountInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/AccountInfo#, error) |
| 100 | |
| 101 | // StreamNameBySubject returns a stream matching given subject. |
| 102 | StreamNameBySubjectscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JetStreamManager#StreamNameBySubject.(string, ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) (string, error) |
| 103 | } |
| 104 | |
| 105 | // StreamConfig will determine the properties for a stream. |
| 106 | // There are sensible defaults for most. If no subjects are |
| 107 | // given the name will be used as the only subject. |
| 108 | type StreamConfigscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig# struct { |
| 109 | // Name is the name of the stream. It is required and must be unique |
| 110 | // across the JetStream account. |
| 111 | // |
| 112 | // Name Names cannot contain whitespace, ., *, >, path separators |
| 113 | // (forward or backwards slash), and non-printable characters. |
| 114 | Namescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Name. string `json:"name"` |
| 115 | |
| 116 | // Description is an optional description of the stream. |
| 117 | Descriptionscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Description. string `json:"description,omitempty"` |
| 118 | |
| 119 | // Subjects is a list of subjects that the stream is listening on. |
| 120 | // Wildcards are supported. Subjects cannot be set if the stream is |
| 121 | // created as a mirror. |
| 122 | Subjectsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Subjects. []string `json:"subjects,omitempty"` |
| 123 | |
| 124 | // Retention defines the message retention policy for the stream. |
| 125 | // Defaults to LimitsPolicy. |
| 126 | Retentionscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Retention. RetentionPolicyscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RetentionPolicy# `json:"retention"` |
| 127 | |
| 128 | // MaxConsumers specifies the maximum number of consumers allowed for |
| 129 | // the stream. |
| 130 | MaxConsumersscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#MaxConsumers. int `json:"max_consumers"` |
| 131 | |
| 132 | // MaxMsgs is the maximum number of messages the stream will store. |
| 133 | // After reaching the limit, stream adheres to the discard policy. |
| 134 | // If not set, server default is -1 (unlimited). |
| 135 | MaxMsgsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#MaxMsgs. int64 `json:"max_msgs"` |
| 136 | |
| 137 | // MaxBytes is the maximum total size of messages the stream will store. |
| 138 | // After reaching the limit, stream adheres to the discard policy. |
| 139 | // If not set, server default is -1 (unlimited). |
| 140 | MaxBytesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#MaxBytes. int64 `json:"max_bytes"` |
| 141 | |
| 142 | // Discard defines the policy for handling messages when the stream |
| 143 | // reaches its limits in terms of number of messages or total bytes. |
| 144 | Discardscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Discard. DiscardPolicyscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/DiscardPolicy# `json:"discard"` |
| 145 | |
| 146 | // DiscardNewPerSubject is a flag to enable discarding new messages per |
| 147 | // subject when limits are reached. Requires DiscardPolicy to be |
| 148 | // DiscardNew and the MaxMsgsPerSubject to be set. |
| 149 | DiscardNewPerSubjectscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#DiscardNewPerSubject. bool `json:"discard_new_per_subject,omitempty"` |
| 150 | |
| 151 | // MaxAge is the maximum age of messages that the stream will retain. |
| 152 | MaxAgescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#MaxAge. timescip-go gomod github.com/golang/go/src go1.25.0 time/.Durationscip-go gomod github.com/golang/go/src go1.25.0 time/Duration# `json:"max_age"` |
| 153 | |
| 154 | // MaxMsgsPerSubject is the maximum number of messages per subject that |
| 155 | // the stream will retain. |
| 156 | MaxMsgsPerSubjectscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#MaxMsgsPerSubject. int64 `json:"max_msgs_per_subject"` |
| 157 | |
| 158 | // MaxMsgSize is the maximum size of any single message in the stream. |
| 159 | MaxMsgSizescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#MaxMsgSize. int32 `json:"max_msg_size,omitempty"` |
| 160 | |
| 161 | // Storage specifies the type of storage backend used for the stream |
| 162 | // (file or memory). |
| 163 | Storagescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Storage. StorageTypescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StorageType# `json:"storage"` |
| 164 | |
| 165 | // Replicas is the number of stream replicas in clustered JetStream. |
| 166 | // Defaults to 1, maximum is 5. |
| 167 | Replicasscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Replicas. int `json:"num_replicas"` |
| 168 | |
| 169 | // NoAck is a flag to disable acknowledging messages received by this |
| 170 | // stream. |
| 171 | // |
| 172 | // If set to true, publish methods from the JetStream client will not |
| 173 | // work as expected, since they rely on acknowledgements. Core NATS |
| 174 | // publish methods should be used instead. Note that this will make |
| 175 | // message delivery less reliable. |
| 176 | NoAckscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#NoAck. bool `json:"no_ack,omitempty"` |
| 177 | |
| 178 | // Duplicates is the window within which to track duplicate messages. |
| 179 | // If not set, server default is 2 minutes. |
| 180 | Duplicatesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Duplicates. timescip-go gomod github.com/golang/go/src go1.25.0 time/.Durationscip-go gomod github.com/golang/go/src go1.25.0 time/Duration# `json:"duplicate_window,omitempty"` |
| 181 | |
| 182 | // Placement is used to declare where the stream should be placed via |
| 183 | // tags and/or an explicit cluster name. |
| 184 | Placementscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Placement. *Placementscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Placement# `json:"placement,omitempty"` |
| 185 | |
| 186 | // Mirror defines the configuration for mirroring another stream. |
| 187 | Mirrorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Mirror. *StreamSourcescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource# `json:"mirror,omitempty"` |
| 188 | |
| 189 | // Sources is a list of other streams this stream sources messages from. |
| 190 | Sourcesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Sources. []*StreamSourcescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource# `json:"sources,omitempty"` |
| 191 | |
| 192 | // Sealed streams do not allow messages to be published or deleted via limits or API, |
| 193 | // sealed streams can not be unsealed via configuration update. Can only |
| 194 | // be set on already created streams via the Update API. |
| 195 | Sealedscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Sealed. bool `json:"sealed,omitempty"` |
| 196 | |
| 197 | // DenyDelete restricts the ability to delete messages from a stream via |
| 198 | // the API. Defaults to false. |
| 199 | DenyDeletescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#DenyDelete. bool `json:"deny_delete,omitempty"` |
| 200 | |
| 201 | // DenyPurge restricts the ability to purge messages from a stream via |
| 202 | // the API. Defaults to false. |
| 203 | DenyPurgescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#DenyPurge. bool `json:"deny_purge,omitempty"` |
| 204 | |
| 205 | // AllowRollup allows the use of the Nats-Rollup header to replace all |
| 206 | // contents of a stream, or subject in a stream, with a single new |
| 207 | // message. |
| 208 | AllowRollupscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#AllowRollup. bool `json:"allow_rollup_hdrs,omitempty"` |
| 209 | |
| 210 | // Compression specifies the message storage compression algorithm. |
| 211 | // Defaults to NoCompression. |
| 212 | Compressionscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Compression. StoreCompressionscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StoreCompression# `json:"compression"` |
| 213 | |
| 214 | // FirstSeq is the initial sequence number of the first message in the |
| 215 | // stream. |
| 216 | FirstSeqscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#FirstSeq. uint64 `json:"first_seq,omitempty"` |
| 217 | |
| 218 | // SubjectTransform allows applying a transformation to matching |
| 219 | // messages' subjects. |
| 220 | SubjectTransformscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#SubjectTransform. *SubjectTransformConfigscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/SubjectTransformConfig# `json:"subject_transform,omitempty"` |
| 221 | |
| 222 | // RePublish allows immediate republishing a message to the configured |
| 223 | // subject after it's stored. |
| 224 | RePublishscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#RePublish. *RePublishscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RePublish# `json:"republish,omitempty"` |
| 225 | |
| 226 | // AllowDirect enables direct access to individual messages using direct |
| 227 | // get API. Defaults to false. |
| 228 | AllowDirectscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#AllowDirect. bool `json:"allow_direct"` |
| 229 | |
| 230 | // MirrorDirect enables direct access to individual messages from the |
| 231 | // origin stream using direct get API. Defaults to false. |
| 232 | MirrorDirectscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#MirrorDirect. bool `json:"mirror_direct"` |
| 233 | |
| 234 | // ConsumerLimits defines limits of certain values that consumers can |
| 235 | // set, defaults for those who don't set these settings |
| 236 | ConsumerLimitsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#ConsumerLimits. StreamConsumerLimitsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConsumerLimits# `json:"consumer_limits,omitempty"` |
| 237 | |
| 238 | // Metadata is a set of application-defined key-value pairs for |
| 239 | // associating metadata on the stream. This feature requires nats-server |
| 240 | // v2.10.0 or later. |
| 241 | Metadatascip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Metadata. map[string]string `json:"metadata,omitempty"` |
| 242 | |
| 243 | // Template identifies the template that manages the Stream. Deprecated: |
| 244 | // This feature is no longer supported. |
| 245 | Templatescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Template. string `json:"template_owner,omitempty"` |
| 246 | |
| 247 | // AllowMsgTTL allows header initiated per-message TTLs. |
| 248 | // This feature requires nats-server v2.11.0 or later. |
| 249 | AllowMsgTTLscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#AllowMsgTTL. bool `json:"allow_msg_ttl"` |
| 250 | |
| 251 | // Enables and sets a duration for adding server markers for delete, purge and max age limits. |
| 252 | // This feature requires nats-server v2.11.0 or later. |
| 253 | SubjectDeleteMarkerTTLscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#SubjectDeleteMarkerTTL. timescip-go gomod github.com/golang/go/src go1.25.0 time/.Durationscip-go gomod github.com/golang/go/src go1.25.0 time/Duration# `json:"subject_delete_marker_ttl,omitempty"` |
| 254 | } |
| 255 | |
| 256 | // SubjectTransformConfig is for applying a subject transform (to matching messages) before doing anything else when a new message is received. |
| 257 | type SubjectTransformConfigscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/SubjectTransformConfig# struct { |
| 258 | Sourcescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/SubjectTransformConfig#Source. string `json:"src,omitempty"` |
| 259 | Destinationscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/SubjectTransformConfig#Destination. string `json:"dest"` |
| 260 | } |
| 261 | |
| 262 | // RePublish is for republishing messages once committed to a stream. The original |
| 263 | // subject cis remapped from the subject pattern to the destination pattern. |
| 264 | type RePublishscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RePublish# struct { |
| 265 | Sourcescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RePublish#Source. string `json:"src,omitempty"` |
| 266 | Destinationscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RePublish#Destination. string `json:"dest"` |
| 267 | HeadersOnlyscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RePublish#HeadersOnly. bool `json:"headers_only,omitempty"` |
| 268 | } |
| 269 | |
| 270 | // Placement is used to guide placement of streams in clustered JetStream. |
| 271 | type Placementscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Placement# struct { |
| 272 | Clusterscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Placement#Cluster. string `json:"cluster"` |
| 273 | Tagsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Placement#Tags. []string `json:"tags,omitempty"` |
| 274 | } |
| 275 | |
| 276 | // StreamSource dictates how streams can source from other streams. |
| 277 | type StreamSourcescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource# struct { |
| 278 | Namescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#Name. string `json:"name"` |
| 279 | OptStartSeqscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#OptStartSeq. uint64 `json:"opt_start_seq,omitempty"` |
| 280 | OptStartTimescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#OptStartTime. *timescip-go gomod github.com/golang/go/src go1.25.0 time/.Timescip-go gomod github.com/golang/go/src go1.25.0 time/Time# `json:"opt_start_time,omitempty"` |
| 281 | FilterSubjectscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#FilterSubject. string `json:"filter_subject,omitempty"` |
| 282 | SubjectTransformsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#SubjectTransforms. []SubjectTransformConfigscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/SubjectTransformConfig# `json:"subject_transforms,omitempty"` |
| 283 | Externalscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#External. *ExternalStreamscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ExternalStream# `json:"external,omitempty"` |
| 284 | Domainscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#Domain. string `json:"-"` |
| 285 | } |
| 286 | |
| 287 | // ExternalStream allows you to qualify access to a stream source in another |
| 288 | // account. |
| 289 | type ExternalStreamscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ExternalStream# struct { |
| 290 | APIPrefixscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ExternalStream#APIPrefix. string `json:"api"` |
| 291 | DeliverPrefixscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ExternalStream#DeliverPrefix. string `json:"deliver,omitempty"` |
| 292 | } |
| 293 | |
| 294 | // StreamConsumerLimits are the limits for a consumer on a stream. |
| 295 | // These can be overridden on a per consumer basis. |
| 296 | type StreamConsumerLimitsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConsumerLimits# struct { |
| 297 | InactiveThresholdscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConsumerLimits#InactiveThreshold. timescip-go gomod github.com/golang/go/src go1.25.0 time/.Durationscip-go gomod github.com/golang/go/src go1.25.0 time/Duration# `json:"inactive_threshold,omitempty"` |
| 298 | MaxAckPendingscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConsumerLimits#MaxAckPending. int `json:"max_ack_pending,omitempty"` |
| 299 | } |
| 300 | |
| 301 | // Helper for copying when we do not want to change user's version. |
| 302 | func (ss *StreamSourcescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#) copyscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#copy().() *StreamSourcescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource# { |
| 303 | nss := *ss |
| 304 | // Check pointers |
| 305 | if ss.OptStartTimescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#OptStartTime. != nil { |
| 306 | t := *ss.OptStartTimescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#OptStartTime. |
| 307 | nss.OptStartTimescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#OptStartTime. = &t |
| 308 | } |
| 309 | if ss.Externalscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#External. != nil { |
| 310 | ext := *ss.Externalscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#External. |
| 311 | nss.Externalscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#External. = &ext |
| 312 | } |
| 313 | return &nss |
| 314 | } |
| 315 | |
| 316 | // If we have a Domain, convert to the appropriate ext.APIPrefix. |
| 317 | // This will change the stream source, so should be a copy passed in. |
| 318 | func (ss *StreamSourcescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#) convertDomainscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#convertDomain().() error { |
| 319 | if ss.Domainscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#Domain. == _EMPTY_scip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/_EMPTY_. { |
| 320 | return nil |
| 321 | } |
| 322 | if ss.Externalscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#External. != nil { |
| 323 | // These should be mutually exclusive. |
| 324 | // TODO(dlc) - Make generic? |
| 325 | return errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Newscip-go gomod github.com/golang/go/src go1.25.0 errors/New().("nats: domain and external are both set") |
| 326 | } |
| 327 | ss.Externalscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#External. = &ExternalStreamscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ExternalStream#{APIPrefixscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ExternalStream#APIPrefix.: fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().(jsExtDomainTscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsExtDomainT., ss.Domainscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#Domain.)} |
| 328 | return nil |
| 329 | } |
| 330 | |
| 331 | // apiResponse is a standard response from the JetStream JSON API |
| 332 | type apiResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse# struct { |
| 333 | Typescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Type. string `json:"type"` |
| 334 | Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. *APIErrorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/APIError# `json:"error,omitempty"` |
| 335 | } |
| 336 | |
| 337 | // apiPaged includes variables used to create paged responses from the JSON API |
| 338 | type apiPagedscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiPaged# struct { |
| 339 | Totalscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiPaged#Total. int `json:"total"` |
| 340 | Offsetscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiPaged#Offset. int `json:"offset"` |
| 341 | Limitscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiPaged#Limit. int `json:"limit"` |
| 342 | } |
| 343 | |
| 344 | // apiPagedRequest includes parameters allowing specific pages to be requested |
| 345 | // from APIs responding with apiPaged. |
| 346 | type apiPagedRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiPagedRequest# struct { |
| 347 | Offsetscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiPagedRequest#Offset. int `json:"offset,omitempty"` |
| 348 | } |
| 349 | |
| 350 | // AccountInfo contains info about the JetStream usage from the current account. |
| 351 | type AccountInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/AccountInfo# struct { |
| 352 | Tierscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/AccountInfo#Tier. |
| 353 | Domainscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/AccountInfo#Domain. string `json:"domain"` |
| 354 | APIscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/AccountInfo#API. APIStatsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/APIStats# `json:"api"` |
| 355 | Tiersscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/AccountInfo#Tiers. map[string]Tierscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Tier# `json:"tiers"` |
| 356 | } |
| 357 | |
| 358 | type Tierscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Tier# struct { |
| 359 | Memoryscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Tier#Memory. uint64 `json:"memory"` |
| 360 | Storescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Tier#Store. uint64 `json:"storage"` |
| 361 | ReservedMemoryscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Tier#ReservedMemory. uint64 `json:"reserved_memory"` |
| 362 | ReservedStorescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Tier#ReservedStore. uint64 `json:"reserved_storage"` |
| 363 | Streamsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Tier#Streams. int `json:"streams"` |
| 364 | Consumersscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Tier#Consumers. int `json:"consumers"` |
| 365 | Limitsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Tier#Limits. AccountLimitsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/AccountLimits# `json:"limits"` |
| 366 | } |
| 367 | |
| 368 | // APIStats reports on API calls to JetStream for this account. |
| 369 | type APIStatsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/APIStats# struct { |
| 370 | Levelscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/APIStats#Level. int `json:"level"` |
| 371 | Totalscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/APIStats#Total. uint64 `json:"total"` |
| 372 | Errorsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/APIStats#Errors. uint64 `json:"errors"` |
| 373 | Inflightscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/APIStats#Inflight. uint64 `json:"inflight,omitempty"` |
| 374 | } |
| 375 | |
| 376 | // AccountLimits includes the JetStream limits of the current account. |
| 377 | type AccountLimitsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/AccountLimits# struct { |
| 378 | MaxMemoryscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/AccountLimits#MaxMemory. int64 `json:"max_memory"` |
| 379 | MaxStorescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/AccountLimits#MaxStore. int64 `json:"max_storage"` |
| 380 | MaxStreamsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/AccountLimits#MaxStreams. int `json:"max_streams"` |
| 381 | MaxConsumersscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/AccountLimits#MaxConsumers. int `json:"max_consumers"` |
| 382 | MaxAckPendingscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/AccountLimits#MaxAckPending. int `json:"max_ack_pending"` |
| 383 | MemoryMaxStreamBytesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/AccountLimits#MemoryMaxStreamBytes. int64 `json:"memory_max_stream_bytes"` |
| 384 | StoreMaxStreamBytesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/AccountLimits#StoreMaxStreamBytes. int64 `json:"storage_max_stream_bytes"` |
| 385 | MaxBytesRequiredscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/AccountLimits#MaxBytesRequired. bool `json:"max_bytes_required"` |
| 386 | } |
| 387 | |
| 388 | type accountInfoResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/accountInfoResponse# struct { |
| 389 | apiResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/accountInfoResponse#apiResponse. |
| 390 | AccountInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/accountInfoResponse#AccountInfo. |
| 391 | } |
| 392 | |
| 393 | // AccountInfo fetches account information from the server, containing details |
| 394 | // about the account associated with this JetStream connection. If account is |
| 395 | // not enabled for JetStream, ErrJetStreamNotEnabledForAccount is returned. |
| 396 | // |
| 397 | // If the server does not have JetStream enabled, ErrJetStreamNotEnabled is |
| 398 | // returned (for a single server setup). For clustered topologies, AccountInfo |
| 399 | // will time out. |
| 400 | func (js *jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#) AccountInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#AccountInfo().(opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) (*AccountInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/AccountInfo#, error) { |
| 401 | o, cancel, err := getJSContextOptsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/getJSContextOpts().(js.optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts., opts...) |
| 402 | if err != nil { |
| 403 | return nil, err |
| 404 | } |
| 405 | if cancel != nil { |
| 406 | defer cancel() |
| 407 | } |
| 408 | |
| 409 | resp, err := js.apiRequestWithContextscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiRequestWithContext().(o.ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx., js.apiSubjscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiSubj().(apiAccountInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiAccountInfo.), nil) |
| 410 | if err != nil { |
| 411 | // todo maybe nats server should never have no responder on this subject and always respond if they know there is no js to be had |
| 412 | if errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Isscip-go gomod github.com/golang/go/src go1.25.0 errors/Is().(err, ErrNoRespondersscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrNoResponders.) { |
| 413 | err = ErrJetStreamNotEnabledscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrJetStreamNotEnabled. |
| 414 | } |
| 415 | return nil, err |
| 416 | } |
| 417 | var info accountInfoResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/accountInfoResponse# |
| 418 | if err := jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Unmarshal().(resp.Datascip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Msg#Data., &info); err != nil { |
| 419 | return nil, err |
| 420 | } |
| 421 | if info.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. != nil { |
| 422 | // Internally checks based on error code instead of description match. |
| 423 | if errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Isscip-go gomod github.com/golang/go/src go1.25.0 errors/Is().(info.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error., ErrJetStreamNotEnabledForAccountscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrJetStreamNotEnabledForAccount.) { |
| 424 | return nil, ErrJetStreamNotEnabledForAccountscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrJetStreamNotEnabledForAccount. |
| 425 | } |
| 426 | return nil, info.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. |
| 427 | } |
| 428 | |
| 429 | return &info.AccountInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/accountInfoResponse#AccountInfo., nil |
| 430 | } |
| 431 | |
| 432 | type createConsumerRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/createConsumerRequest# struct { |
| 433 | Streamscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/createConsumerRequest#Stream. string `json:"stream_name"` |
| 434 | Configscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/createConsumerRequest#Config. *ConsumerConfigscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerConfig# `json:"config"` |
| 435 | } |
| 436 | |
| 437 | type consumerResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerResponse# struct { |
| 438 | apiResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerResponse#apiResponse. |
| 439 | *ConsumerInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerResponse#ConsumerInfo. |
| 440 | } |
| 441 | |
| 442 | // AddConsumer adds a consumer to a stream. |
| 443 | // If the consumer already exists, and the configuration is the same, it |
| 444 | // will return the existing consumer. |
| 445 | // If the consumer already exists, and the configuration is different, it |
| 446 | // will return ErrConsumerNameAlreadyInUse. |
| 447 | func (js *jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#) AddConsumerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#AddConsumer().(stream string, cfg *ConsumerConfigscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerConfig#, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) (*ConsumerInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerInfo#, error) { |
| 448 | if cfg == nil { |
| 449 | cfg = &ConsumerConfigscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerConfig#{} |
| 450 | } |
| 451 | consumerName := cfg.Namescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerConfig#Name. |
| 452 | if consumerName == _EMPTY_scip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/_EMPTY_. { |
| 453 | consumerName = cfg.Durablescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerConfig#Durable. |
| 454 | } |
| 455 | if consumerName != _EMPTY_scip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/_EMPTY_. { |
| 456 | consInfo, err := js.ConsumerInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#ConsumerInfo().(stream, consumerName, opts...) |
| 457 | if err != nil && !errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Isscip-go gomod github.com/golang/go/src go1.25.0 errors/Is().(err, ErrConsumerNotFoundscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrConsumerNotFound.) && !errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Isscip-go gomod github.com/golang/go/src go1.25.0 errors/Is().(err, ErrStreamNotFoundscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrStreamNotFound.) { |
| 458 | return nil, err |
| 459 | } |
| 460 | |
| 461 | if consInfo != nil { |
| 462 | sameConfig := checkConfigscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/checkConfig().(&consInfo.Configscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerInfo#Config., cfg) |
| 463 | if sameConfig != nil { |
| 464 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Errorf().("%w: creating consumer %q on stream %q", ErrConsumerNameAlreadyInUsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrConsumerNameAlreadyInUse., consumerName, stream) |
| 465 | } else { |
| 466 | return consInfo, nil |
| 467 | } |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | return js.upsertConsumerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#upsertConsumer().(stream, consumerName, cfg, opts...) |
| 472 | } |
| 473 | |
| 474 | func (js *jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#) UpdateConsumerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#UpdateConsumer().(stream string, cfg *ConsumerConfigscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerConfig#, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) (*ConsumerInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerInfo#, error) { |
| 475 | if cfg == nil { |
| 476 | return nil, ErrConsumerConfigRequiredscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrConsumerConfigRequired. |
| 477 | } |
| 478 | consumerName := cfg.Namescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerConfig#Name. |
| 479 | if consumerName == _EMPTY_scip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/_EMPTY_. { |
| 480 | consumerName = cfg.Durablescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerConfig#Durable. |
| 481 | } |
| 482 | if consumerName == _EMPTY_scip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/_EMPTY_. { |
| 483 | return nil, ErrConsumerNameRequiredscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrConsumerNameRequired. |
| 484 | } |
| 485 | return js.upsertConsumerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#upsertConsumer().(stream, consumerName, cfg, opts...) |
| 486 | } |
| 487 | |
| 488 | func (js *jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#) upsertConsumerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#upsertConsumer().(stream, consumerName string, cfg *ConsumerConfigscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerConfig#, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) (*ConsumerInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerInfo#, error) { |
| 489 | if err := checkStreamNamescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/checkStreamName().(stream); err != nil { |
| 490 | return nil, err |
| 491 | } |
| 492 | o, cancel, err := getJSContextOptsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/getJSContextOpts().(js.optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts., opts...) |
| 493 | if err != nil { |
| 494 | return nil, err |
| 495 | } |
| 496 | if cancel != nil { |
| 497 | defer cancel() |
| 498 | } |
| 499 | |
| 500 | req, err := jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Marshal().(&createConsumerRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/createConsumerRequest#{Streamscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/createConsumerRequest#Stream.: stream, Configscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/createConsumerRequest#Config.: cfg}) |
| 501 | if err != nil { |
| 502 | return nil, err |
| 503 | } |
| 504 | |
| 505 | var ccSubj string |
| 506 | if consumerName == _EMPTY_scip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/_EMPTY_. { |
| 507 | // if consumer name is empty (neither Durable nor Name is set), use the legacy ephemeral endpoint |
| 508 | ccSubj = fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().(apiLegacyConsumerCreateTscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiLegacyConsumerCreateT., stream) |
| 509 | } else if err := checkConsumerNamescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/checkConsumerName().(consumerName); err != nil { |
| 510 | return nil, err |
| 511 | } else if js.ncscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#nc..serverMinVersionscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Conn#serverMinVersion().(2, 9, 0) { |
| 512 | if cfg.Durablescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerConfig#Durable. != "" && js.optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts..featureFlagsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#featureFlags..useDurableConsumerCreatescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/featureFlags#useDurableConsumerCreate. { |
| 513 | // if user set the useDurableConsumerCreate flag, use the legacy DURABLE.CREATE endpoint |
| 514 | ccSubj = fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().(apiDurableCreateTscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiDurableCreateT., stream, consumerName) |
| 515 | } else if cfg.FilterSubjectscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerConfig#FilterSubject. == _EMPTY_scip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/_EMPTY_. || cfg.FilterSubjectscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerConfig#FilterSubject. == ">" { |
| 516 | // if filter subject is empty or ">", use the endpoint without filter subject |
| 517 | ccSubj = fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().(apiConsumerCreateTscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiConsumerCreateT., stream, consumerName) |
| 518 | } else { |
| 519 | // safeguard against passing invalid filter subject in request subject |
| 520 | if cfg.FilterSubjectscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerConfig#FilterSubject.[0] == '.' || cfg.FilterSubjectscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerConfig#FilterSubject.[len(cfg.FilterSubjectscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerConfig#FilterSubject.)-1] == '.' { |
| 521 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Errorf().("%w: %q", ErrInvalidFilterSubjectscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrInvalidFilterSubject., cfg.FilterSubjectscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerConfig#FilterSubject.) |
| 522 | } |
| 523 | // if filter subject is not empty, use the endpoint with filter subject |
| 524 | ccSubj = fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().(apiConsumerCreateWithFilterSubjectTscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiConsumerCreateWithFilterSubjectT., stream, consumerName, cfg.FilterSubjectscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerConfig#FilterSubject.) |
| 525 | } |
| 526 | } else { |
| 527 | if cfg.Durablescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerConfig#Durable. != "" { |
| 528 | // if Durable is set, use the DURABLE.CREATE endpoint |
| 529 | ccSubj = fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().(apiDurableCreateTscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiDurableCreateT., stream, consumerName) |
| 530 | } else { |
| 531 | // if Durable is not set, use the legacy ephemeral endpoint |
| 532 | ccSubj = fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().(apiLegacyConsumerCreateTscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiLegacyConsumerCreateT., stream) |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | resp, err := js.apiRequestWithContextscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiRequestWithContext().(o.ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx., js.apiSubjscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiSubj().(ccSubj), req) |
| 537 | if err != nil { |
| 538 | if errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Isscip-go gomod github.com/golang/go/src go1.25.0 errors/Is().(err, ErrNoRespondersscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrNoResponders.) { |
| 539 | err = ErrJetStreamNotEnabledscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrJetStreamNotEnabled. |
| 540 | } |
| 541 | return nil, err |
| 542 | } |
| 543 | var info consumerResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerResponse# |
| 544 | err = jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Unmarshal().(resp.Datascip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Msg#Data., &info) |
| 545 | if err != nil { |
| 546 | return nil, err |
| 547 | } |
| 548 | if info.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. != nil { |
| 549 | if errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Isscip-go gomod github.com/golang/go/src go1.25.0 errors/Is().(info.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error., ErrStreamNotFoundscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrStreamNotFound.) { |
| 550 | return nil, ErrStreamNotFoundscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrStreamNotFound. |
| 551 | } |
| 552 | if errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Isscip-go gomod github.com/golang/go/src go1.25.0 errors/Is().(info.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error., ErrConsumerNotFoundscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrConsumerNotFound.) { |
| 553 | return nil, ErrConsumerNotFoundscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrConsumerNotFound. |
| 554 | } |
| 555 | return nil, info.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. |
| 556 | } |
| 557 | |
| 558 | if info.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. == nil && info.ConsumerInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerResponse#ConsumerInfo. == nil { |
| 559 | return nil, ErrConsumerCreationResponseEmptyscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrConsumerCreationResponseEmpty. |
| 560 | } |
| 561 | |
| 562 | // check whether multiple filter subjects (if used) are reflected in the returned ConsumerInfo |
| 563 | if len(cfg.FilterSubjectsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerConfig#FilterSubjects.) != 0 && len(info.Configscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerInfo#Config..FilterSubjectsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerConfig#FilterSubjects.) == 0 { |
| 564 | return nil, ErrConsumerMultipleFilterSubjectsNotSupportedscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrConsumerMultipleFilterSubjectsNotSupported. |
| 565 | } |
| 566 | return info.ConsumerInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerResponse#ConsumerInfo., nil |
| 567 | } |
| 568 | |
| 569 | // consumerDeleteResponse is the response for a Consumer delete request. |
| 570 | type consumerDeleteResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerDeleteResponse# struct { |
| 571 | apiResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerDeleteResponse#apiResponse. |
| 572 | Successscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerDeleteResponse#Success. bool `json:"success,omitempty"` |
| 573 | } |
| 574 | |
| 575 | func checkStreamNamescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/checkStreamName().(stream string) error { |
| 576 | if stream == _EMPTY_scip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/_EMPTY_. { |
| 577 | return ErrStreamNameRequiredscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrStreamNameRequired. |
| 578 | } |
| 579 | if stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.ContainsAnyscip-go gomod github.com/golang/go/src go1.25.0 strings/ContainsAny().(stream, ". ") { |
| 580 | return ErrInvalidStreamNamescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrInvalidStreamName. |
| 581 | } |
| 582 | return nil |
| 583 | } |
| 584 | |
| 585 | // Check that the consumer name is not empty and is valid (does not contain "." and " "). |
| 586 | // Additional consumer name validation is done in nats-server. |
| 587 | // Returns ErrConsumerNameRequired if consumer name is empty, ErrInvalidConsumerName is invalid, otherwise nil |
| 588 | func checkConsumerNamescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/checkConsumerName().(consumer string) error { |
| 589 | if consumer == _EMPTY_scip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/_EMPTY_. { |
| 590 | return ErrConsumerNameRequiredscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrConsumerNameRequired. |
| 591 | } |
| 592 | if stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.ContainsAnyscip-go gomod github.com/golang/go/src go1.25.0 strings/ContainsAny().(consumer, ". ") { |
| 593 | return ErrInvalidConsumerNamescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrInvalidConsumerName. |
| 594 | } |
| 595 | return nil |
| 596 | } |
| 597 | |
| 598 | // DeleteConsumer deletes a Consumer. |
| 599 | func (js *jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#) DeleteConsumerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#DeleteConsumer().(stream, consumer string, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) error { |
| 600 | if err := checkStreamNamescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/checkStreamName().(stream); err != nil { |
| 601 | return err |
| 602 | } |
| 603 | if err := checkConsumerNamescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/checkConsumerName().(consumer); err != nil { |
| 604 | return err |
| 605 | } |
| 606 | o, cancel, err := getJSContextOptsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/getJSContextOpts().(js.optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts., opts...) |
| 607 | if err != nil { |
| 608 | return err |
| 609 | } |
| 610 | if cancel != nil { |
| 611 | defer cancel() |
| 612 | } |
| 613 | |
| 614 | dcSubj := js.apiSubjscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiSubj().(fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().(apiConsumerDeleteTscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiConsumerDeleteT., stream, consumer)) |
| 615 | r, err := js.apiRequestWithContextscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiRequestWithContext().(o.ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx., dcSubj, nil) |
| 616 | if err != nil { |
| 617 | return err |
| 618 | } |
| 619 | var resp consumerDeleteResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerDeleteResponse# |
| 620 | if err := jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Unmarshal().(r.Datascip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Msg#Data., &resp); err != nil { |
| 621 | return err |
| 622 | } |
| 623 | |
| 624 | if resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. != nil { |
| 625 | if errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Isscip-go gomod github.com/golang/go/src go1.25.0 errors/Is().(resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error., ErrConsumerNotFoundscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrConsumerNotFound.) { |
| 626 | return ErrConsumerNotFoundscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrConsumerNotFound. |
| 627 | } |
| 628 | return resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. |
| 629 | } |
| 630 | return nil |
| 631 | } |
| 632 | |
| 633 | // ConsumerInfo returns information about a Consumer. |
| 634 | func (js *jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#) ConsumerInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#ConsumerInfo().(stream, consumer string, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) (*ConsumerInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerInfo#, error) { |
| 635 | if err := checkStreamNamescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/checkStreamName().(stream); err != nil { |
| 636 | return nil, err |
| 637 | } |
| 638 | if err := checkConsumerNamescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/checkConsumerName().(consumer); err != nil { |
| 639 | return nil, err |
| 640 | } |
| 641 | o, cancel, err := getJSContextOptsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/getJSContextOpts().(js.optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts., opts...) |
| 642 | if err != nil { |
| 643 | return nil, err |
| 644 | } |
| 645 | if cancel != nil { |
| 646 | defer cancel() |
| 647 | } |
| 648 | return js.getConsumerInfoContextscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#getConsumerInfoContext().(o.ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx., stream, consumer) |
| 649 | } |
| 650 | |
| 651 | // consumerLister fetches pages of ConsumerInfo objects. This object is not |
| 652 | // safe to use for multiple threads. |
| 653 | type consumerListerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister# struct { |
| 654 | streamscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#stream. string |
| 655 | jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#js. *jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js# |
| 656 | |
| 657 | errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#err. error |
| 658 | offsetscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#offset. int |
| 659 | pagescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#page. []*ConsumerInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerInfo# |
| 660 | pageInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#pageInfo. *apiPagedscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiPaged# |
| 661 | } |
| 662 | |
| 663 | // consumersRequest is the type used for Consumers requests. |
| 664 | type consumersRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumersRequest# struct { |
| 665 | apiPagedRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumersRequest#apiPagedRequest. |
| 666 | } |
| 667 | |
| 668 | // consumerListResponse is the response for a Consumers List request. |
| 669 | type consumerListResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerListResponse# struct { |
| 670 | apiResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerListResponse#apiResponse. |
| 671 | apiPagedscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerListResponse#apiPaged. |
| 672 | Consumersscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerListResponse#Consumers. []*ConsumerInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerInfo# `json:"consumers"` |
| 673 | } |
| 674 | |
| 675 | // Next fetches the next ConsumerInfo page. |
| 676 | func (c *consumerListerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#) Nextscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#Next().() bool { |
| 677 | if c.errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#err. != nil { |
| 678 | return false |
| 679 | } |
| 680 | if err := checkStreamNamescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/checkStreamName().(c.streamscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#stream.); err != nil { |
| 681 | c.errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#err. = err |
| 682 | return false |
| 683 | } |
| 684 | if c.pageInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#pageInfo. != nil && c.offsetscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#offset. >= c.pageInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#pageInfo..Totalscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiPaged#Total. { |
| 685 | return false |
| 686 | } |
| 687 | |
| 688 | req, err := jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Marshal().(consumersRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumersRequest#{ |
| 689 | apiPagedRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumersRequest#apiPagedRequest.: apiPagedRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiPagedRequest#{Offsetscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiPagedRequest#Offset.: c.offsetscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#offset.}, |
| 690 | }) |
| 691 | if err != nil { |
| 692 | c.errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#err. = err |
| 693 | return false |
| 694 | } |
| 695 | |
| 696 | var cancel contextscip-go gomod github.com/golang/go/src go1.25.0 context/.CancelFuncscip-go gomod github.com/golang/go/src go1.25.0 context/CancelFunc# |
| 697 | ctx := c.jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#js..optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts..ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx. |
| 698 | if ctx == nil { |
| 699 | ctx, cancel = contextscip-go gomod github.com/golang/go/src go1.25.0 context/.WithTimeoutscip-go gomod github.com/golang/go/src go1.25.0 context/WithTimeout().(contextscip-go gomod github.com/golang/go/src go1.25.0 context/.Backgroundscip-go gomod github.com/golang/go/src go1.25.0 context/Background().(), c.jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#js..optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts..waitscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#wait.) |
| 700 | defer cancel() |
| 701 | } |
| 702 | |
| 703 | clSubj := c.jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#js..apiSubjscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiSubj().(fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().(apiConsumerListTscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiConsumerListT., c.streamscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#stream.)) |
| 704 | r, err := c.jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#js..apiRequestWithContextscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiRequestWithContext().(ctx, clSubj, req) |
| 705 | if err != nil { |
| 706 | c.errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#err. = err |
| 707 | return false |
| 708 | } |
| 709 | var resp consumerListResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerListResponse# |
| 710 | if err := jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Unmarshal().(r.Datascip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Msg#Data., &resp); err != nil { |
| 711 | c.errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#err. = err |
| 712 | return false |
| 713 | } |
| 714 | if resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. != nil { |
| 715 | c.errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#err. = resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. |
| 716 | return false |
| 717 | } |
| 718 | |
| 719 | c.pageInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#pageInfo. = &resp.apiPagedscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerListResponse#apiPaged. |
| 720 | c.pagescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#page. = resp.Consumersscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerListResponse#Consumers. |
| 721 | c.offsetscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#offset. += len(c.pagescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#page.) |
| 722 | return true |
| 723 | } |
| 724 | |
| 725 | // Page returns the current ConsumerInfo page. |
| 726 | func (c *consumerListerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#) Pagescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#Page().() []*ConsumerInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerInfo# { |
| 727 | return c.pagescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#page. |
| 728 | } |
| 729 | |
| 730 | // Err returns any errors found while fetching pages. |
| 731 | func (c *consumerListerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#) Errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#Err().() error { |
| 732 | return c.errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#err. |
| 733 | } |
| 734 | |
| 735 | // Consumers is used to retrieve a list of ConsumerInfo objects. |
| 736 | func (jsc *jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#) Consumersscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#Consumers().(stream string, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) <-chan *ConsumerInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerInfo# { |
| 737 | o, cancel, err := getJSContextOptsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/getJSContextOpts().(jsc.optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts., opts...) |
| 738 | if err != nil { |
| 739 | return nil |
| 740 | } |
| 741 | |
| 742 | ch := make(chan *ConsumerInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerInfo#) |
| 743 | l := &consumerListerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#{jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#js.: &jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#{ncscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#nc.: jsc.ncscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#nc., optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts.: o}, streamscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#stream.: stream} |
| 744 | go func() { |
| 745 | if cancel != nil { |
| 746 | defer cancel() |
| 747 | } |
| 748 | defer close(ch) |
| 749 | for l.Nextscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#Next().() { |
| 750 | for _, info := range l.Pagescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerLister#Page().() { |
| 751 | select { |
| 752 | case ch <- info: |
| 753 | case <-o.ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx..Donescip-go gomod github.com/golang/go/src go1.25.0 context/Context#Done().(): |
| 754 | return |
| 755 | } |
| 756 | } |
| 757 | } |
| 758 | }() |
| 759 | |
| 760 | return ch |
| 761 | } |
| 762 | |
| 763 | // ConsumersInfo is used to retrieve a list of ConsumerInfo objects. |
| 764 | // Deprecated: Use Consumers() instead. |
| 765 | func (jsc *jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#) ConsumersInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#ConsumersInfo().(stream string, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) <-chan *ConsumerInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ConsumerInfo# { |
| 766 | return jsc.Consumersscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#Consumers().(stream, opts...) |
| 767 | } |
| 768 | |
| 769 | type consumerNamesListerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister# struct { |
| 770 | streamscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#stream. string |
| 771 | jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#js. *jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js# |
| 772 | |
| 773 | errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#err. error |
| 774 | offsetscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#offset. int |
| 775 | pagescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#page. []string |
| 776 | pageInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#pageInfo. *apiPagedscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiPaged# |
| 777 | } |
| 778 | |
| 779 | // consumerNamesListResponse is the response for a Consumers Names List request. |
| 780 | type consumerNamesListResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesListResponse# struct { |
| 781 | apiResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesListResponse#apiResponse. |
| 782 | apiPagedscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesListResponse#apiPaged. |
| 783 | Consumersscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesListResponse#Consumers. []string `json:"consumers"` |
| 784 | } |
| 785 | |
| 786 | // Next fetches the next consumer names page. |
| 787 | func (c *consumerNamesListerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#) Nextscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#Next().() bool { |
| 788 | if c.errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#err. != nil { |
| 789 | return false |
| 790 | } |
| 791 | if err := checkStreamNamescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/checkStreamName().(c.streamscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#stream.); err != nil { |
| 792 | c.errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#err. = err |
| 793 | return false |
| 794 | } |
| 795 | if c.pageInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#pageInfo. != nil && c.offsetscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#offset. >= c.pageInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#pageInfo..Totalscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiPaged#Total. { |
| 796 | return false |
| 797 | } |
| 798 | |
| 799 | var cancel contextscip-go gomod github.com/golang/go/src go1.25.0 context/.CancelFuncscip-go gomod github.com/golang/go/src go1.25.0 context/CancelFunc# |
| 800 | ctx := c.jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#js..optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts..ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx. |
| 801 | if ctx == nil { |
| 802 | ctx, cancel = contextscip-go gomod github.com/golang/go/src go1.25.0 context/.WithTimeoutscip-go gomod github.com/golang/go/src go1.25.0 context/WithTimeout().(contextscip-go gomod github.com/golang/go/src go1.25.0 context/.Backgroundscip-go gomod github.com/golang/go/src go1.25.0 context/Background().(), c.jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#js..optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts..waitscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#wait.) |
| 803 | defer cancel() |
| 804 | } |
| 805 | |
| 806 | req, err := jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Marshal().(consumersRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumersRequest#{ |
| 807 | apiPagedRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumersRequest#apiPagedRequest.: apiPagedRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiPagedRequest#{Offsetscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiPagedRequest#Offset.: c.offsetscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#offset.}, |
| 808 | }) |
| 809 | if err != nil { |
| 810 | c.errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#err. = err |
| 811 | return false |
| 812 | } |
| 813 | clSubj := c.jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#js..apiSubjscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiSubj().(fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().(apiConsumerNamesTscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiConsumerNamesT., c.streamscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#stream.)) |
| 814 | r, err := c.jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#js..apiRequestWithContextscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiRequestWithContext().(ctx, clSubj, req) |
| 815 | if err != nil { |
| 816 | c.errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#err. = err |
| 817 | return false |
| 818 | } |
| 819 | var resp consumerNamesListResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesListResponse# |
| 820 | if err := jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Unmarshal().(r.Datascip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Msg#Data., &resp); err != nil { |
| 821 | c.errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#err. = err |
| 822 | return false |
| 823 | } |
| 824 | if resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. != nil { |
| 825 | c.errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#err. = resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. |
| 826 | return false |
| 827 | } |
| 828 | |
| 829 | c.pageInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#pageInfo. = &resp.apiPagedscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesListResponse#apiPaged. |
| 830 | c.pagescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#page. = resp.Consumersscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesListResponse#Consumers. |
| 831 | c.offsetscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#offset. += len(c.pagescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#page.) |
| 832 | return true |
| 833 | } |
| 834 | |
| 835 | // Page returns the current ConsumerInfo page. |
| 836 | func (c *consumerNamesListerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#) Pagescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#Page().() []string { |
| 837 | return c.pagescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#page. |
| 838 | } |
| 839 | |
| 840 | // Err returns any errors found while fetching pages. |
| 841 | func (c *consumerNamesListerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#) Errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#Err().() error { |
| 842 | return c.errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#err. |
| 843 | } |
| 844 | |
| 845 | // ConsumerNames is used to retrieve a list of Consumer names. |
| 846 | func (jsc *jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#) ConsumerNamesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#ConsumerNames().(stream string, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) <-chan string { |
| 847 | o, cancel, err := getJSContextOptsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/getJSContextOpts().(jsc.optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts., opts...) |
| 848 | if err != nil { |
| 849 | return nil |
| 850 | } |
| 851 | |
| 852 | ch := make(chan string) |
| 853 | l := &consumerNamesListerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#{streamscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#stream.: stream, jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#js.: &jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#{ncscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#nc.: jsc.ncscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#nc., optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts.: o}} |
| 854 | go func() { |
| 855 | if cancel != nil { |
| 856 | defer cancel() |
| 857 | } |
| 858 | defer close(ch) |
| 859 | for l.Nextscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#Next().() { |
| 860 | for _, info := range l.Pagescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/consumerNamesLister#Page().() { |
| 861 | select { |
| 862 | case ch <- info: |
| 863 | case <-o.ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx..Donescip-go gomod github.com/golang/go/src go1.25.0 context/Context#Done().(): |
| 864 | return |
| 865 | } |
| 866 | } |
| 867 | } |
| 868 | }() |
| 869 | |
| 870 | return ch |
| 871 | } |
| 872 | |
| 873 | // streamCreateResponse stream creation. |
| 874 | type streamCreateResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamCreateResponse# struct { |
| 875 | apiResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamCreateResponse#apiResponse. |
| 876 | *StreamInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamCreateResponse#StreamInfo. |
| 877 | } |
| 878 | |
| 879 | func (js *jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#) AddStreamscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#AddStream().(cfg *StreamConfigscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) (*StreamInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo#, error) { |
| 880 | if cfg == nil { |
| 881 | return nil, ErrStreamConfigRequiredscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrStreamConfigRequired. |
| 882 | } |
| 883 | if err := checkStreamNamescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/checkStreamName().(cfg.Namescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Name.); err != nil { |
| 884 | return nil, err |
| 885 | } |
| 886 | o, cancel, err := getJSContextOptsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/getJSContextOpts().(js.optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts., opts...) |
| 887 | if err != nil { |
| 888 | return nil, err |
| 889 | } |
| 890 | if cancel != nil { |
| 891 | defer cancel() |
| 892 | } |
| 893 | |
| 894 | // In case we need to change anything, copy so we do not change the caller's version. |
| 895 | ncfg := *cfg |
| 896 | |
| 897 | // If we have a mirror and an external domain, convert to ext.APIPrefix. |
| 898 | if cfg.Mirrorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Mirror. != nil && cfg.Mirrorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Mirror..Domainscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#Domain. != _EMPTY_scip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/_EMPTY_. { |
| 899 | // Copy so we do not change the caller's version. |
| 900 | ncfg.Mirrorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Mirror. = ncfg.Mirrorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Mirror..copyscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#copy().() |
| 901 | if err := ncfg.Mirrorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Mirror..convertDomainscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#convertDomain().(); err != nil { |
| 902 | return nil, err |
| 903 | } |
| 904 | } |
| 905 | // Check sources for the same. |
| 906 | if len(ncfg.Sourcesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Sources.) > 0 { |
| 907 | ncfg.Sourcesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Sources. = append([]*StreamSourcescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#(nil), ncfg.Sourcesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Sources....) |
| 908 | for i, ss := range ncfg.Sourcesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Sources. { |
| 909 | if ss.Domainscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#Domain. != _EMPTY_scip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/_EMPTY_. { |
| 910 | ncfg.Sourcesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Sources.[i] = ss.copyscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#copy().() |
| 911 | if err := ncfg.Sourcesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Sources.[i].convertDomainscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#convertDomain().(); err != nil { |
| 912 | return nil, err |
| 913 | } |
| 914 | } |
| 915 | } |
| 916 | } |
| 917 | |
| 918 | req, err := jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Marshal().(&ncfg) |
| 919 | if err != nil { |
| 920 | return nil, err |
| 921 | } |
| 922 | |
| 923 | csSubj := js.apiSubjscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiSubj().(fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().(apiStreamCreateTscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiStreamCreateT., cfg.Namescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Name.)) |
| 924 | r, err := js.apiRequestWithContextscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiRequestWithContext().(o.ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx., csSubj, req) |
| 925 | if err != nil { |
| 926 | return nil, err |
| 927 | } |
| 928 | var resp streamCreateResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamCreateResponse# |
| 929 | if err := jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Unmarshal().(r.Datascip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Msg#Data., &resp); err != nil { |
| 930 | return nil, err |
| 931 | } |
| 932 | if resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. != nil { |
| 933 | if errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Isscip-go gomod github.com/golang/go/src go1.25.0 errors/Is().(resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error., ErrStreamNameAlreadyInUsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrStreamNameAlreadyInUse.) { |
| 934 | return nil, ErrStreamNameAlreadyInUsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrStreamNameAlreadyInUse. |
| 935 | } |
| 936 | return nil, resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. |
| 937 | } |
| 938 | |
| 939 | // check that input subject transform (if used) is reflected in the returned ConsumerInfo |
| 940 | if cfg.SubjectTransformscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#SubjectTransform. != nil && resp.StreamInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamCreateResponse#StreamInfo..Configscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo#Config..SubjectTransformscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#SubjectTransform. == nil { |
| 941 | return nil, ErrStreamSubjectTransformNotSupportedscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrStreamSubjectTransformNotSupported. |
| 942 | } |
| 943 | if len(cfg.Sourcesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Sources.) != 0 { |
| 944 | if len(cfg.Sourcesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Sources.) != len(resp.Configscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo#Config..Sourcesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Sources.) { |
| 945 | return nil, ErrStreamSourceNotSupportedscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrStreamSourceNotSupported. |
| 946 | } |
| 947 | for i := range cfg.Sourcesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Sources. { |
| 948 | if len(cfg.Sourcesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Sources.[i].SubjectTransformsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#SubjectTransforms.) != 0 && len(resp.Sourcesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo#Sources.[i].SubjectTransformsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSourceInfo#SubjectTransforms.) == 0 { |
| 949 | return nil, ErrStreamSourceMultipleSubjectTransformsNotSupportedscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrStreamSourceMultipleSubjectTransformsNotSupported. |
| 950 | } |
| 951 | } |
| 952 | } |
| 953 | |
| 954 | return resp.StreamInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamCreateResponse#StreamInfo., nil |
| 955 | } |
| 956 | |
| 957 | type ( |
| 958 | // StreamInfoRequest contains additional option to return |
| 959 | StreamInfoRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfoRequest# struct { |
| 960 | apiPagedRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfoRequest#apiPagedRequest. |
| 961 | // DeletedDetails when true includes information about deleted messages |
| 962 | DeletedDetailsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfoRequest#DeletedDetails. bool `json:"deleted_details,omitempty"` |
| 963 | // SubjectsFilter when set, returns information on the matched subjects |
| 964 | SubjectsFilterscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfoRequest#SubjectsFilter. string `json:"subjects_filter,omitempty"` |
| 965 | } |
| 966 | streamInfoResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamInfoResponse# = struct { |
| 967 | apiResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamInfoResponse#apiResponse. |
| 968 | apiPagedscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamInfoResponse#apiPaged. |
| 969 | *StreamInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamInfoResponse#StreamInfo. |
| 970 | } |
| 971 | ) |
| 972 | |
| 973 | func (js *jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#) StreamInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#StreamInfo().(stream string, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) (*StreamInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo#, error) { |
| 974 | if err := checkStreamNamescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/checkStreamName().(stream); err != nil { |
| 975 | return nil, err |
| 976 | } |
| 977 | o, cancel, err := getJSContextOptsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/getJSContextOpts().(js.optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts., opts...) |
| 978 | if err != nil { |
| 979 | return nil, err |
| 980 | } |
| 981 | if cancel != nil { |
| 982 | defer cancel() |
| 983 | } |
| 984 | |
| 985 | var i int |
| 986 | var subjectMessagesMap map[string]uint64 |
| 987 | var req []byte |
| 988 | var requestPayload bool |
| 989 | |
| 990 | var siOpts StreamInfoRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfoRequest# |
| 991 | if o.streamInfoOptsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#streamInfoOpts. != nil { |
| 992 | requestPayload = true |
| 993 | siOpts = *o.streamInfoOptsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#streamInfoOpts. |
| 994 | } |
| 995 | |
| 996 | for { |
| 997 | if requestPayload { |
| 998 | siOpts.Offsetscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiPagedRequest#Offset. = i |
| 999 | if req, err = jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Marshal().(&siOpts); err != nil { |
| 1000 | return nil, err |
| 1001 | } |
| 1002 | } |
| 1003 | |
| 1004 | siSubj := js.apiSubjscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiSubj().(fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().(apiStreamInfoTscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiStreamInfoT., stream)) |
| 1005 | |
| 1006 | r, err := js.apiRequestWithContextscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiRequestWithContext().(o.ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx., siSubj, req) |
| 1007 | if err != nil { |
| 1008 | return nil, err |
| 1009 | } |
| 1010 | |
| 1011 | var resp streamInfoResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamInfoResponse# |
| 1012 | if err := jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Unmarshal().(r.Datascip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Msg#Data., &resp); err != nil { |
| 1013 | return nil, err |
| 1014 | } |
| 1015 | |
| 1016 | if resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. != nil { |
| 1017 | if errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Isscip-go gomod github.com/golang/go/src go1.25.0 errors/Is().(resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error., ErrStreamNotFoundscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrStreamNotFound.) { |
| 1018 | return nil, ErrStreamNotFoundscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrStreamNotFound. |
| 1019 | } |
| 1020 | return nil, resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. |
| 1021 | } |
| 1022 | |
| 1023 | var total int |
| 1024 | // for backwards compatibility |
| 1025 | if resp.Totalscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiPaged#Total. != 0 { |
| 1026 | total = resp.Totalscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiPaged#Total. |
| 1027 | } else { |
| 1028 | total = len(resp.Statescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo#State..Subjectsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamState#Subjects.) |
| 1029 | } |
| 1030 | |
| 1031 | if requestPayload && len(resp.StreamInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamInfoResponse#StreamInfo..Statescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo#State..Subjectsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamState#Subjects.) > 0 { |
| 1032 | if subjectMessagesMap == nil { |
| 1033 | subjectMessagesMap = make(map[string]uint64, total) |
| 1034 | } |
| 1035 | |
| 1036 | for k, j := range resp.Statescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo#State..Subjectsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamState#Subjects. { |
| 1037 | subjectMessagesMap[k] = j |
| 1038 | i++ |
| 1039 | } |
| 1040 | } |
| 1041 | |
| 1042 | if i >= total { |
| 1043 | if requestPayload { |
| 1044 | resp.StreamInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamInfoResponse#StreamInfo..Statescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo#State..Subjectsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamState#Subjects. = subjectMessagesMap |
| 1045 | } |
| 1046 | return resp.StreamInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamInfoResponse#StreamInfo., nil |
| 1047 | } |
| 1048 | } |
| 1049 | } |
| 1050 | |
| 1051 | // StreamInfo shows config and current state for this stream. |
| 1052 | type StreamInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo# struct { |
| 1053 | Configscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo#Config. StreamConfigscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig# `json:"config"` |
| 1054 | Createdscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo#Created. timescip-go gomod github.com/golang/go/src go1.25.0 time/.Timescip-go gomod github.com/golang/go/src go1.25.0 time/Time# `json:"created"` |
| 1055 | Statescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo#State. StreamStatescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamState# `json:"state"` |
| 1056 | Clusterscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo#Cluster. *ClusterInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ClusterInfo# `json:"cluster,omitempty"` |
| 1057 | Mirrorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo#Mirror. *StreamSourceInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSourceInfo# `json:"mirror,omitempty"` |
| 1058 | Sourcesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo#Sources. []*StreamSourceInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSourceInfo# `json:"sources,omitempty"` |
| 1059 | Alternatesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo#Alternates. []*StreamAlternatescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamAlternate# `json:"alternates,omitempty"` |
| 1060 | } |
| 1061 | |
| 1062 | // StreamAlternate is an alternate stream represented by a mirror. |
| 1063 | type StreamAlternatescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamAlternate# struct { |
| 1064 | Namescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamAlternate#Name. string `json:"name"` |
| 1065 | Domainscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamAlternate#Domain. string `json:"domain,omitempty"` |
| 1066 | Clusterscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamAlternate#Cluster. string `json:"cluster"` |
| 1067 | } |
| 1068 | |
| 1069 | // StreamSourceInfo shows information about an upstream stream source. |
| 1070 | type StreamSourceInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSourceInfo# struct { |
| 1071 | Namescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSourceInfo#Name. string `json:"name"` |
| 1072 | Lagscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSourceInfo#Lag. uint64 `json:"lag"` |
| 1073 | Activescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSourceInfo#Active. timescip-go gomod github.com/golang/go/src go1.25.0 time/.Durationscip-go gomod github.com/golang/go/src go1.25.0 time/Duration# `json:"active"` |
| 1074 | Externalscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSourceInfo#External. *ExternalStreamscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ExternalStream# `json:"external"` |
| 1075 | Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSourceInfo#Error. *APIErrorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/APIError# `json:"error"` |
| 1076 | FilterSubjectscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSourceInfo#FilterSubject. string `json:"filter_subject,omitempty"` |
| 1077 | SubjectTransformsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSourceInfo#SubjectTransforms. []SubjectTransformConfigscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/SubjectTransformConfig# `json:"subject_transforms,omitempty"` |
| 1078 | } |
| 1079 | |
| 1080 | // StreamState is information about the given stream. |
| 1081 | type StreamStatescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamState# struct { |
| 1082 | Msgsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamState#Msgs. uint64 `json:"messages"` |
| 1083 | Bytesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamState#Bytes. uint64 `json:"bytes"` |
| 1084 | FirstSeqscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamState#FirstSeq. uint64 `json:"first_seq"` |
| 1085 | FirstTimescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamState#FirstTime. timescip-go gomod github.com/golang/go/src go1.25.0 time/.Timescip-go gomod github.com/golang/go/src go1.25.0 time/Time# `json:"first_ts"` |
| 1086 | LastSeqscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamState#LastSeq. uint64 `json:"last_seq"` |
| 1087 | LastTimescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamState#LastTime. timescip-go gomod github.com/golang/go/src go1.25.0 time/.Timescip-go gomod github.com/golang/go/src go1.25.0 time/Time# `json:"last_ts"` |
| 1088 | Consumersscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamState#Consumers. int `json:"consumer_count"` |
| 1089 | Deletedscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamState#Deleted. []uint64 `json:"deleted"` |
| 1090 | NumDeletedscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamState#NumDeleted. int `json:"num_deleted"` |
| 1091 | NumSubjectsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamState#NumSubjects. uint64 `json:"num_subjects"` |
| 1092 | Subjectsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamState#Subjects. map[string]uint64 `json:"subjects"` |
| 1093 | } |
| 1094 | |
| 1095 | // ClusterInfo shows information about the underlying set of servers |
| 1096 | // that make up the stream or consumer. |
| 1097 | type ClusterInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ClusterInfo# struct { |
| 1098 | Namescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ClusterInfo#Name. string `json:"name,omitempty"` |
| 1099 | RaftGroupscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ClusterInfo#RaftGroup. string `json:"raft_group,omitempty"` |
| 1100 | Leaderscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ClusterInfo#Leader. string `json:"leader,omitempty"` |
| 1101 | LeaderSincescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ClusterInfo#LeaderSince. *timescip-go gomod github.com/golang/go/src go1.25.0 time/.Timescip-go gomod github.com/golang/go/src go1.25.0 time/Time# `json:"leader_since,omitempty"` |
| 1102 | SystemAccscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ClusterInfo#SystemAcc. bool `json:"system_account,omitempty"` |
| 1103 | TrafficAccscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ClusterInfo#TrafficAcc. string `json:"traffic_account,omitempty"` |
| 1104 | Replicasscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ClusterInfo#Replicas. []*PeerInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/PeerInfo# `json:"replicas,omitempty"` |
| 1105 | } |
| 1106 | |
| 1107 | // PeerInfo shows information about all the peers in the cluster that |
| 1108 | // are supporting the stream or consumer. |
| 1109 | type PeerInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/PeerInfo# struct { |
| 1110 | Namescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/PeerInfo#Name. string `json:"name"` |
| 1111 | Currentscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/PeerInfo#Current. bool `json:"current"` |
| 1112 | Offlinescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/PeerInfo#Offline. bool `json:"offline,omitempty"` |
| 1113 | Activescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/PeerInfo#Active. timescip-go gomod github.com/golang/go/src go1.25.0 time/.Durationscip-go gomod github.com/golang/go/src go1.25.0 time/Duration# `json:"active"` |
| 1114 | Lagscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/PeerInfo#Lag. uint64 `json:"lag,omitempty"` |
| 1115 | } |
| 1116 | |
| 1117 | // UpdateStream updates a Stream. |
| 1118 | func (js *jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#) UpdateStreamscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#UpdateStream().(cfg *StreamConfigscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) (*StreamInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo#, error) { |
| 1119 | if cfg == nil { |
| 1120 | return nil, ErrStreamConfigRequiredscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrStreamConfigRequired. |
| 1121 | } |
| 1122 | if err := checkStreamNamescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/checkStreamName().(cfg.Namescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Name.); err != nil { |
| 1123 | return nil, err |
| 1124 | } |
| 1125 | o, cancel, err := getJSContextOptsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/getJSContextOpts().(js.optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts., opts...) |
| 1126 | if err != nil { |
| 1127 | return nil, err |
| 1128 | } |
| 1129 | if cancel != nil { |
| 1130 | defer cancel() |
| 1131 | } |
| 1132 | |
| 1133 | req, err := jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Marshal().(cfg) |
| 1134 | if err != nil { |
| 1135 | return nil, err |
| 1136 | } |
| 1137 | |
| 1138 | usSubj := js.apiSubjscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiSubj().(fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().(apiStreamUpdateTscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiStreamUpdateT., cfg.Namescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Name.)) |
| 1139 | r, err := js.apiRequestWithContextscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiRequestWithContext().(o.ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx., usSubj, req) |
| 1140 | if err != nil { |
| 1141 | return nil, err |
| 1142 | } |
| 1143 | var resp streamInfoResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamInfoResponse# |
| 1144 | if err := jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Unmarshal().(r.Datascip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Msg#Data., &resp); err != nil { |
| 1145 | return nil, err |
| 1146 | } |
| 1147 | if resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. != nil { |
| 1148 | if errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Isscip-go gomod github.com/golang/go/src go1.25.0 errors/Is().(resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error., ErrStreamNotFoundscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrStreamNotFound.) { |
| 1149 | return nil, ErrStreamNotFoundscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrStreamNotFound. |
| 1150 | } |
| 1151 | return nil, resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. |
| 1152 | } |
| 1153 | |
| 1154 | // check that input subject transform (if used) is reflected in the returned StreamInfo |
| 1155 | if cfg.SubjectTransformscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#SubjectTransform. != nil && resp.StreamInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamInfoResponse#StreamInfo..Configscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo#Config..SubjectTransformscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#SubjectTransform. == nil { |
| 1156 | return nil, ErrStreamSubjectTransformNotSupportedscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrStreamSubjectTransformNotSupported. |
| 1157 | } |
| 1158 | |
| 1159 | if len(cfg.Sourcesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Sources.) != 0 { |
| 1160 | if len(cfg.Sourcesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Sources.) != len(resp.Configscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo#Config..Sourcesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Sources.) { |
| 1161 | return nil, ErrStreamSourceNotSupportedscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrStreamSourceNotSupported. |
| 1162 | } |
| 1163 | for i := range cfg.Sourcesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Sources. { |
| 1164 | if len(cfg.Sourcesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamConfig#Sources.[i].SubjectTransformsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSource#SubjectTransforms.) != 0 && len(resp.Sourcesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo#Sources.[i].SubjectTransformsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamSourceInfo#SubjectTransforms.) == 0 { |
| 1165 | return nil, ErrStreamSourceMultipleSubjectTransformsNotSupportedscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrStreamSourceMultipleSubjectTransformsNotSupported. |
| 1166 | } |
| 1167 | } |
| 1168 | } |
| 1169 | |
| 1170 | return resp.StreamInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamInfoResponse#StreamInfo., nil |
| 1171 | } |
| 1172 | |
| 1173 | // streamDeleteResponse is the response for a Stream delete request. |
| 1174 | type streamDeleteResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamDeleteResponse# struct { |
| 1175 | apiResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamDeleteResponse#apiResponse. |
| 1176 | Successscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamDeleteResponse#Success. bool `json:"success,omitempty"` |
| 1177 | } |
| 1178 | |
| 1179 | // DeleteStream deletes a Stream. |
| 1180 | func (js *jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#) DeleteStreamscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#DeleteStream().(name string, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) error { |
| 1181 | if err := checkStreamNamescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/checkStreamName().(name); err != nil { |
| 1182 | return err |
| 1183 | } |
| 1184 | o, cancel, err := getJSContextOptsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/getJSContextOpts().(js.optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts., opts...) |
| 1185 | if err != nil { |
| 1186 | return err |
| 1187 | } |
| 1188 | if cancel != nil { |
| 1189 | defer cancel() |
| 1190 | } |
| 1191 | |
| 1192 | dsSubj := js.apiSubjscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiSubj().(fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().(apiStreamDeleteTscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiStreamDeleteT., name)) |
| 1193 | r, err := js.apiRequestWithContextscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiRequestWithContext().(o.ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx., dsSubj, nil) |
| 1194 | if err != nil { |
| 1195 | return err |
| 1196 | } |
| 1197 | var resp streamDeleteResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamDeleteResponse# |
| 1198 | if err := jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Unmarshal().(r.Datascip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Msg#Data., &resp); err != nil { |
| 1199 | return err |
| 1200 | } |
| 1201 | |
| 1202 | if resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. != nil { |
| 1203 | if errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Isscip-go gomod github.com/golang/go/src go1.25.0 errors/Is().(resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error., ErrStreamNotFoundscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrStreamNotFound.) { |
| 1204 | return ErrStreamNotFoundscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrStreamNotFound. |
| 1205 | } |
| 1206 | return resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. |
| 1207 | } |
| 1208 | return nil |
| 1209 | } |
| 1210 | |
| 1211 | type apiMsgGetRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiMsgGetRequest# struct { |
| 1212 | Seqscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiMsgGetRequest#Seq. uint64 `json:"seq,omitempty"` |
| 1213 | LastForscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiMsgGetRequest#LastFor. string `json:"last_by_subj,omitempty"` |
| 1214 | NextForscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiMsgGetRequest#NextFor. string `json:"next_by_subj,omitempty"` |
| 1215 | } |
| 1216 | |
| 1217 | // RawStreamMsg is a raw message stored in JetStream. |
| 1218 | type RawStreamMsgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RawStreamMsg# struct { |
| 1219 | Subjectscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RawStreamMsg#Subject. string |
| 1220 | Sequencescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RawStreamMsg#Sequence. uint64 |
| 1221 | Headerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RawStreamMsg#Header. Headerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Header# |
| 1222 | Datascip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RawStreamMsg#Data. []byte |
| 1223 | Timescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RawStreamMsg#Time. timescip-go gomod github.com/golang/go/src go1.25.0 time/.Timescip-go gomod github.com/golang/go/src go1.25.0 time/Time# |
| 1224 | } |
| 1225 | |
| 1226 | // storedMsg is a raw message stored in JetStream. |
| 1227 | type storedMsgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/storedMsg# struct { |
| 1228 | Subjectscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/storedMsg#Subject. string `json:"subject"` |
| 1229 | Sequencescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/storedMsg#Sequence. uint64 `json:"seq"` |
| 1230 | Headerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/storedMsg#Header. []byte `json:"hdrs,omitempty"` |
| 1231 | Datascip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/storedMsg#Data. []byte `json:"data,omitempty"` |
| 1232 | Timescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/storedMsg#Time. timescip-go gomod github.com/golang/go/src go1.25.0 time/.Timescip-go gomod github.com/golang/go/src go1.25.0 time/Time# `json:"time"` |
| 1233 | } |
| 1234 | |
| 1235 | // apiMsgGetResponse is the response for a Stream get request. |
| 1236 | type apiMsgGetResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiMsgGetResponse# struct { |
| 1237 | apiResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiMsgGetResponse#apiResponse. |
| 1238 | Messagescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiMsgGetResponse#Message. *storedMsgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/storedMsg# `json:"message,omitempty"` |
| 1239 | } |
| 1240 | |
| 1241 | // GetLastMsg retrieves the last raw stream message stored in JetStream by subject. |
| 1242 | func (js *jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#) GetLastMsgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#GetLastMsg().(name, subject string, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) (*RawStreamMsgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RawStreamMsg#, error) { |
| 1243 | return js.getMsgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#getMsg().(name, &apiMsgGetRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiMsgGetRequest#{LastForscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiMsgGetRequest#LastFor.: subject}, opts...) |
| 1244 | } |
| 1245 | |
| 1246 | // GetMsg retrieves a raw stream message stored in JetStream by sequence number. |
| 1247 | func (js *jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#) GetMsgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#GetMsg().(name string, seq uint64, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) (*RawStreamMsgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RawStreamMsg#, error) { |
| 1248 | return js.getMsgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#getMsg().(name, &apiMsgGetRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiMsgGetRequest#{Seqscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiMsgGetRequest#Seq.: seq}, opts...) |
| 1249 | } |
| 1250 | |
| 1251 | // Low level getMsg |
| 1252 | func (js *jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#) getMsgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#getMsg().(name string, mreq *apiMsgGetRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiMsgGetRequest#, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) (*RawStreamMsgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RawStreamMsg#, error) { |
| 1253 | o, cancel, err := getJSContextOptsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/getJSContextOpts().(js.optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts., opts...) |
| 1254 | if err != nil { |
| 1255 | return nil, err |
| 1256 | } |
| 1257 | if cancel != nil { |
| 1258 | defer cancel() |
| 1259 | } |
| 1260 | |
| 1261 | if err := checkStreamNamescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/checkStreamName().(name); err != nil { |
| 1262 | return nil, err |
| 1263 | } |
| 1264 | |
| 1265 | var apiSubj string |
| 1266 | if o.directGetscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#directGet. && mreq.LastForscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiMsgGetRequest#LastFor. != _EMPTY_scip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/_EMPTY_. { |
| 1267 | apiSubj = apiDirectMsgGetLastBySubjectTscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiDirectMsgGetLastBySubjectT. |
| 1268 | dsSubj := js.apiSubjscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiSubj().(fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().(apiSubj, name, mreq.LastForscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiMsgGetRequest#LastFor.)) |
| 1269 | r, err := js.apiRequestWithContextscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiRequestWithContext().(o.ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx., dsSubj, nil) |
| 1270 | if err != nil { |
| 1271 | return nil, err |
| 1272 | } |
| 1273 | return convertDirectGetMsgResponseToMsgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/convertDirectGetMsgResponseToMsg().(name, r) |
| 1274 | } |
| 1275 | |
| 1276 | if o.directGetscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#directGet. { |
| 1277 | apiSubj = apiDirectMsgGetTscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiDirectMsgGetT. |
| 1278 | mreq.NextForscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiMsgGetRequest#NextFor. = o.directNextForscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#directNextFor. |
| 1279 | } else { |
| 1280 | apiSubj = apiMsgGetTscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiMsgGetT. |
| 1281 | } |
| 1282 | |
| 1283 | req, err := jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Marshal().(mreq) |
| 1284 | if err != nil { |
| 1285 | return nil, err |
| 1286 | } |
| 1287 | |
| 1288 | dsSubj := js.apiSubjscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiSubj().(fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().(apiSubj, name)) |
| 1289 | r, err := js.apiRequestWithContextscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiRequestWithContext().(o.ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx., dsSubj, req) |
| 1290 | if err != nil { |
| 1291 | return nil, err |
| 1292 | } |
| 1293 | |
| 1294 | if o.directGetscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#directGet. { |
| 1295 | return convertDirectGetMsgResponseToMsgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/convertDirectGetMsgResponseToMsg().(name, r) |
| 1296 | } |
| 1297 | |
| 1298 | var resp apiMsgGetResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiMsgGetResponse# |
| 1299 | if err := jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Unmarshal().(r.Datascip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Msg#Data., &resp); err != nil { |
| 1300 | return nil, err |
| 1301 | } |
| 1302 | if resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. != nil { |
| 1303 | if errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Isscip-go gomod github.com/golang/go/src go1.25.0 errors/Is().(resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error., ErrMsgNotFoundscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrMsgNotFound.) { |
| 1304 | return nil, ErrMsgNotFoundscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrMsgNotFound. |
| 1305 | } |
| 1306 | if errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Isscip-go gomod github.com/golang/go/src go1.25.0 errors/Is().(resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error., ErrStreamNotFoundscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrStreamNotFound.) { |
| 1307 | return nil, ErrStreamNotFoundscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrStreamNotFound. |
| 1308 | } |
| 1309 | return nil, resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. |
| 1310 | } |
| 1311 | |
| 1312 | msg := resp.Messagescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiMsgGetResponse#Message. |
| 1313 | |
| 1314 | var hdr Headerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Header# |
| 1315 | if len(msg.Headerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/storedMsg#Header.) > 0 { |
| 1316 | hdr, err = DecodeHeadersMsgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/DecodeHeadersMsg().(msg.Headerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/storedMsg#Header.) |
| 1317 | if err != nil { |
| 1318 | return nil, err |
| 1319 | } |
| 1320 | } |
| 1321 | |
| 1322 | return &RawStreamMsgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RawStreamMsg#{ |
| 1323 | Subjectscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RawStreamMsg#Subject.: msg.Subjectscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/storedMsg#Subject., |
| 1324 | Sequencescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RawStreamMsg#Sequence.: msg.Sequencescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/storedMsg#Sequence., |
| 1325 | Headerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RawStreamMsg#Header.: hdr, |
| 1326 | Datascip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RawStreamMsg#Data.: msg.Datascip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/storedMsg#Data., |
| 1327 | Timescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RawStreamMsg#Time.: msg.Timescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/storedMsg#Time., |
| 1328 | }, nil |
| 1329 | } |
| 1330 | |
| 1331 | func convertDirectGetMsgResponseToMsgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/convertDirectGetMsgResponseToMsg().(name string, r *Msgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Msg#) (*RawStreamMsgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RawStreamMsg#, error) { |
| 1332 | // Check for 404/408. We would get a no-payload message and a "Status" header |
| 1333 | if len(r.Datascip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Msg#Data.) == 0 { |
| 1334 | val := r.Headerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Msg#Header..Getscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Header#Get().(statusHdrscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/statusHdr.) |
| 1335 | if val != _EMPTY_scip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/_EMPTY_. { |
| 1336 | switch val { |
| 1337 | case noMessagesStsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/noMessagesSts.: |
| 1338 | return nil, ErrMsgNotFoundscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrMsgNotFound. |
| 1339 | default: |
| 1340 | desc := r.Headerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Msg#Header..Getscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Header#Get().(descrHdrscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/descrHdr.) |
| 1341 | if desc == _EMPTY_scip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/_EMPTY_. { |
| 1342 | desc = "unable to get message" |
| 1343 | } |
| 1344 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Errorf().("nats: %s", desc) |
| 1345 | } |
| 1346 | } |
| 1347 | } |
| 1348 | // Check for headers that give us the required information to |
| 1349 | // reconstruct the message. |
| 1350 | if len(r.Headerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Msg#Header.) == 0 { |
| 1351 | return nil, errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Newscip-go gomod github.com/golang/go/src go1.25.0 errors/New().("nats: response should have headers") |
| 1352 | } |
| 1353 | stream := r.Headerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Msg#Header..Getscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Header#Get().(JSStreamscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSStream.) |
| 1354 | if stream == _EMPTY_scip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/_EMPTY_. { |
| 1355 | return nil, errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Newscip-go gomod github.com/golang/go/src go1.25.0 errors/New().("nats: missing stream header") |
| 1356 | } |
| 1357 | |
| 1358 | // Mirrors can now answer direct gets, so removing check for name equality. |
| 1359 | // TODO(dlc) - We could have server also have a header with origin and check that? |
| 1360 | |
| 1361 | seqStr := r.Headerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Msg#Header..Getscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Header#Get().(JSSequencescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSSequence.) |
| 1362 | if seqStr == _EMPTY_scip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/_EMPTY_. { |
| 1363 | return nil, errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Newscip-go gomod github.com/golang/go/src go1.25.0 errors/New().("nats: missing sequence header") |
| 1364 | } |
| 1365 | seq, err := strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.ParseUintscip-go gomod github.com/golang/go/src go1.25.0 strconv/ParseUint().(seqStr, 10, 64) |
| 1366 | if err != nil { |
| 1367 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Errorf().("nats: invalid sequence header '%s': %v", seqStr, err) |
| 1368 | } |
| 1369 | timeStr := r.Headerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Msg#Header..Getscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Header#Get().(JSTimeStampscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSTimeStamp.) |
| 1370 | if timeStr == _EMPTY_scip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/_EMPTY_. { |
| 1371 | return nil, errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Newscip-go gomod github.com/golang/go/src go1.25.0 errors/New().("nats: missing timestamp header") |
| 1372 | } |
| 1373 | // Temporary code: the server in main branch is sending with format |
| 1374 | // "2006-01-02 15:04:05.999999999 +0000 UTC", but will be changed |
| 1375 | // to use format RFC3339Nano. Because of server test deps/cycle, |
| 1376 | // support both until the server PR lands. |
| 1377 | tm, err := timescip-go gomod github.com/golang/go/src go1.25.0 time/.Parsescip-go gomod github.com/golang/go/src go1.25.0 time/Parse().(timescip-go gomod github.com/golang/go/src go1.25.0 time/.RFC3339Nanoscip-go gomod github.com/golang/go/src go1.25.0 time/RFC3339Nano., timeStr) |
| 1378 | if err != nil { |
| 1379 | tm, err = timescip-go gomod github.com/golang/go/src go1.25.0 time/.Parsescip-go gomod github.com/golang/go/src go1.25.0 time/Parse().("2006-01-02 15:04:05.999999999 +0000 UTC", timeStr) |
| 1380 | if err != nil { |
| 1381 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Errorf().("nats: invalid timestamp header '%s': %v", timeStr, err) |
| 1382 | } |
| 1383 | } |
| 1384 | subj := r.Headerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Msg#Header..Getscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Header#Get().(JSSubjectscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSSubject.) |
| 1385 | if subj == _EMPTY_scip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/_EMPTY_. { |
| 1386 | return nil, errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Newscip-go gomod github.com/golang/go/src go1.25.0 errors/New().("nats: missing subject header") |
| 1387 | } |
| 1388 | return &RawStreamMsgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RawStreamMsg#{ |
| 1389 | Subjectscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RawStreamMsg#Subject.: subj, |
| 1390 | Sequencescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RawStreamMsg#Sequence.: seq, |
| 1391 | Headerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RawStreamMsg#Header.: r.Headerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Msg#Header., |
| 1392 | Datascip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RawStreamMsg#Data.: r.Datascip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Msg#Data., |
| 1393 | Timescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/RawStreamMsg#Time.: tm, |
| 1394 | }, nil |
| 1395 | } |
| 1396 | |
| 1397 | type msgDeleteRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/msgDeleteRequest# struct { |
| 1398 | Seqscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/msgDeleteRequest#Seq. uint64 `json:"seq"` |
| 1399 | NoErasescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/msgDeleteRequest#NoErase. bool `json:"no_erase,omitempty"` |
| 1400 | } |
| 1401 | |
| 1402 | // msgDeleteResponse is the response for a Stream delete request. |
| 1403 | type msgDeleteResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/msgDeleteResponse# struct { |
| 1404 | apiResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/msgDeleteResponse#apiResponse. |
| 1405 | Successscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/msgDeleteResponse#Success. bool `json:"success,omitempty"` |
| 1406 | } |
| 1407 | |
| 1408 | // DeleteMsg deletes a message from a stream. |
| 1409 | // The message is marked as erased, but not overwritten |
| 1410 | func (js *jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#) DeleteMsgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#DeleteMsg().(name string, seq uint64, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) error { |
| 1411 | o, cancel, err := getJSContextOptsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/getJSContextOpts().(js.optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts., opts...) |
| 1412 | if err != nil { |
| 1413 | return err |
| 1414 | } |
| 1415 | if cancel != nil { |
| 1416 | defer cancel() |
| 1417 | } |
| 1418 | |
| 1419 | return js.deleteMsgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#deleteMsg().(o.ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx., name, &msgDeleteRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/msgDeleteRequest#{Seqscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/msgDeleteRequest#Seq.: seq, NoErasescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/msgDeleteRequest#NoErase.: true}) |
| 1420 | } |
| 1421 | |
| 1422 | // SecureDeleteMsg deletes a message from a stream. The deleted message is overwritten with random data |
| 1423 | // As a result, this operation is slower than DeleteMsg() |
| 1424 | func (js *jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#) SecureDeleteMsgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#SecureDeleteMsg().(name string, seq uint64, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) error { |
| 1425 | o, cancel, err := getJSContextOptsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/getJSContextOpts().(js.optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts., opts...) |
| 1426 | if err != nil { |
| 1427 | return err |
| 1428 | } |
| 1429 | if cancel != nil { |
| 1430 | defer cancel() |
| 1431 | } |
| 1432 | |
| 1433 | return js.deleteMsgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#deleteMsg().(o.ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx., name, &msgDeleteRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/msgDeleteRequest#{Seqscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/msgDeleteRequest#Seq.: seq}) |
| 1434 | } |
| 1435 | |
| 1436 | func (js *jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#) deleteMsgscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#deleteMsg().(ctx contextscip-go gomod github.com/golang/go/src go1.25.0 context/.Contextscip-go gomod github.com/golang/go/src go1.25.0 context/Context#, stream string, req *msgDeleteRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/msgDeleteRequest#) error { |
| 1437 | if err := checkStreamNamescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/checkStreamName().(stream); err != nil { |
| 1438 | return err |
| 1439 | } |
| 1440 | reqJSON, err := jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Marshal().(req) |
| 1441 | if err != nil { |
| 1442 | return err |
| 1443 | } |
| 1444 | |
| 1445 | dsSubj := js.apiSubjscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiSubj().(fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().(apiMsgDeleteTscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiMsgDeleteT., stream)) |
| 1446 | r, err := js.apiRequestWithContextscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiRequestWithContext().(ctx, dsSubj, reqJSON) |
| 1447 | if err != nil { |
| 1448 | return err |
| 1449 | } |
| 1450 | var resp msgDeleteResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/msgDeleteResponse# |
| 1451 | if err := jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Unmarshal().(r.Datascip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Msg#Data., &resp); err != nil { |
| 1452 | return err |
| 1453 | } |
| 1454 | if resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. != nil { |
| 1455 | return resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. |
| 1456 | } |
| 1457 | return nil |
| 1458 | } |
| 1459 | |
| 1460 | // StreamPurgeRequest is optional request information to the purge API. |
| 1461 | type StreamPurgeRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamPurgeRequest# struct { |
| 1462 | // Purge up to but not including sequence. |
| 1463 | Sequencescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamPurgeRequest#Sequence. uint64 `json:"seq,omitempty"` |
| 1464 | // Subject to match against messages for the purge command. |
| 1465 | Subjectscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamPurgeRequest#Subject. string `json:"filter,omitempty"` |
| 1466 | // Number of messages to keep. |
| 1467 | Keepscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamPurgeRequest#Keep. uint64 `json:"keep,omitempty"` |
| 1468 | } |
| 1469 | |
| 1470 | type streamPurgeResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamPurgeResponse# struct { |
| 1471 | apiResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamPurgeResponse#apiResponse. |
| 1472 | Successscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamPurgeResponse#Success. bool `json:"success,omitempty"` |
| 1473 | Purgedscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamPurgeResponse#Purged. uint64 `json:"purged"` |
| 1474 | } |
| 1475 | |
| 1476 | // PurgeStream purges messages on a Stream. |
| 1477 | func (js *jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#) PurgeStreamscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#PurgeStream().(stream string, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) error { |
| 1478 | if err := checkStreamNamescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/checkStreamName().(stream); err != nil { |
| 1479 | return err |
| 1480 | } |
| 1481 | var req *StreamPurgeRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamPurgeRequest# |
| 1482 | var ok bool |
| 1483 | for _, opt := range opts { |
| 1484 | // For PurgeStream, only request body opt is relevant |
| 1485 | if req, ok = opt.(*StreamPurgeRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamPurgeRequest#); ok { |
| 1486 | break |
| 1487 | } |
| 1488 | } |
| 1489 | return js.purgeStreamscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#purgeStream().(stream, req) |
| 1490 | } |
| 1491 | |
| 1492 | func (js *jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#) purgeStreamscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#purgeStream().(stream string, req *StreamPurgeRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamPurgeRequest#, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) error { |
| 1493 | o, cancel, err := getJSContextOptsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/getJSContextOpts().(js.optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts., opts...) |
| 1494 | if err != nil { |
| 1495 | return err |
| 1496 | } |
| 1497 | if cancel != nil { |
| 1498 | defer cancel() |
| 1499 | } |
| 1500 | |
| 1501 | var b []byte |
| 1502 | if req != nil { |
| 1503 | if b, err = jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Marshal().(req); err != nil { |
| 1504 | return err |
| 1505 | } |
| 1506 | } |
| 1507 | |
| 1508 | psSubj := js.apiSubjscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiSubj().(fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().(apiStreamPurgeTscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiStreamPurgeT., stream)) |
| 1509 | r, err := js.apiRequestWithContextscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiRequestWithContext().(o.ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx., psSubj, b) |
| 1510 | if err != nil { |
| 1511 | return err |
| 1512 | } |
| 1513 | var resp streamPurgeResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamPurgeResponse# |
| 1514 | if err := jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Unmarshal().(r.Datascip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Msg#Data., &resp); err != nil { |
| 1515 | return err |
| 1516 | } |
| 1517 | if resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. != nil { |
| 1518 | if errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Isscip-go gomod github.com/golang/go/src go1.25.0 errors/Is().(resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error., ErrBadRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrBadRequest.) { |
| 1519 | return fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Errorf().("%w: %s", ErrBadRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrBadRequest., "invalid purge request body") |
| 1520 | } |
| 1521 | return resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. |
| 1522 | } |
| 1523 | return nil |
| 1524 | } |
| 1525 | |
| 1526 | // streamLister fetches pages of StreamInfo objects. This object is not safe |
| 1527 | // to use for multiple threads. |
| 1528 | type streamListerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister# struct { |
| 1529 | jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#js. *jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js# |
| 1530 | pagescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#page. []*StreamInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo# |
| 1531 | errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#err. error |
| 1532 | |
| 1533 | offsetscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#offset. int |
| 1534 | pageInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#pageInfo. *apiPagedscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiPaged# |
| 1535 | } |
| 1536 | |
| 1537 | // streamListResponse list of detailed stream information. |
| 1538 | // A nil request is valid and means all streams. |
| 1539 | type streamListResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamListResponse# struct { |
| 1540 | apiResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamListResponse#apiResponse. |
| 1541 | apiPagedscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamListResponse#apiPaged. |
| 1542 | Streamsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamListResponse#Streams. []*StreamInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo# `json:"streams"` |
| 1543 | } |
| 1544 | |
| 1545 | // streamNamesRequest is used for Stream Name requests. |
| 1546 | type streamNamesRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesRequest# struct { |
| 1547 | apiPagedRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesRequest#apiPagedRequest. |
| 1548 | // These are filters that can be applied to the list. |
| 1549 | Subjectscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesRequest#Subject. string `json:"subject,omitempty"` |
| 1550 | } |
| 1551 | |
| 1552 | // Next fetches the next StreamInfo page. |
| 1553 | func (s *streamListerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#) Nextscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#Next().() bool { |
| 1554 | if s.errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#err. != nil { |
| 1555 | return false |
| 1556 | } |
| 1557 | if s.pageInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#pageInfo. != nil && s.offsetscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#offset. >= s.pageInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#pageInfo..Totalscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiPaged#Total. { |
| 1558 | return false |
| 1559 | } |
| 1560 | |
| 1561 | req, err := jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Marshal().(streamNamesRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesRequest#{ |
| 1562 | apiPagedRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesRequest#apiPagedRequest.: apiPagedRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiPagedRequest#{Offsetscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiPagedRequest#Offset.: s.offsetscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#offset.}, |
| 1563 | Subjectscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesRequest#Subject.: s.jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#js..optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts..streamListSubjectscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#streamListSubject., |
| 1564 | }) |
| 1565 | if err != nil { |
| 1566 | s.errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#err. = err |
| 1567 | return false |
| 1568 | } |
| 1569 | |
| 1570 | var cancel contextscip-go gomod github.com/golang/go/src go1.25.0 context/.CancelFuncscip-go gomod github.com/golang/go/src go1.25.0 context/CancelFunc# |
| 1571 | ctx := s.jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#js..optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts..ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx. |
| 1572 | if ctx == nil { |
| 1573 | ctx, cancel = contextscip-go gomod github.com/golang/go/src go1.25.0 context/.WithTimeoutscip-go gomod github.com/golang/go/src go1.25.0 context/WithTimeout().(contextscip-go gomod github.com/golang/go/src go1.25.0 context/.Backgroundscip-go gomod github.com/golang/go/src go1.25.0 context/Background().(), s.jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#js..optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts..waitscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#wait.) |
| 1574 | defer cancel() |
| 1575 | } |
| 1576 | |
| 1577 | slSubj := s.jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#js..apiSubjscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiSubj().(apiStreamListTscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiStreamListT.) |
| 1578 | r, err := s.jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#js..apiRequestWithContextscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiRequestWithContext().(ctx, slSubj, req) |
| 1579 | if err != nil { |
| 1580 | s.errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#err. = err |
| 1581 | return false |
| 1582 | } |
| 1583 | var resp streamListResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamListResponse# |
| 1584 | if err := jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Unmarshal().(r.Datascip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Msg#Data., &resp); err != nil { |
| 1585 | s.errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#err. = err |
| 1586 | return false |
| 1587 | } |
| 1588 | if resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. != nil { |
| 1589 | s.errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#err. = resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. |
| 1590 | return false |
| 1591 | } |
| 1592 | |
| 1593 | s.pageInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#pageInfo. = &resp.apiPagedscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamListResponse#apiPaged. |
| 1594 | s.pagescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#page. = resp.Streamsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamListResponse#Streams. |
| 1595 | s.offsetscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#offset. += len(s.pagescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#page.) |
| 1596 | return true |
| 1597 | } |
| 1598 | |
| 1599 | // Page returns the current StreamInfo page. |
| 1600 | func (s *streamListerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#) Pagescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#Page().() []*StreamInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo# { |
| 1601 | return s.pagescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#page. |
| 1602 | } |
| 1603 | |
| 1604 | // Err returns any errors found while fetching pages. |
| 1605 | func (s *streamListerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#) Errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#Err().() error { |
| 1606 | return s.errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#err. |
| 1607 | } |
| 1608 | |
| 1609 | // Streams can be used to retrieve a list of StreamInfo objects. |
| 1610 | func (jsc *jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#) Streamsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#Streams().(opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) <-chan *StreamInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo# { |
| 1611 | o, cancel, err := getJSContextOptsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/getJSContextOpts().(jsc.optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts., opts...) |
| 1612 | if err != nil { |
| 1613 | return nil |
| 1614 | } |
| 1615 | |
| 1616 | ch := make(chan *StreamInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo#) |
| 1617 | l := &streamListerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#{jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#js.: &jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#{ncscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#nc.: jsc.ncscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#nc., optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts.: o}} |
| 1618 | go func() { |
| 1619 | if cancel != nil { |
| 1620 | defer cancel() |
| 1621 | } |
| 1622 | defer close(ch) |
| 1623 | for l.Nextscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#Next().() { |
| 1624 | for _, info := range l.Pagescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamLister#Page().() { |
| 1625 | select { |
| 1626 | case ch <- info: |
| 1627 | case <-o.ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx..Donescip-go gomod github.com/golang/go/src go1.25.0 context/Context#Done().(): |
| 1628 | return |
| 1629 | } |
| 1630 | } |
| 1631 | } |
| 1632 | }() |
| 1633 | |
| 1634 | return ch |
| 1635 | } |
| 1636 | |
| 1637 | // StreamsInfo can be used to retrieve a list of StreamInfo objects. |
| 1638 | // Deprecated: Use Streams() instead. |
| 1639 | func (jsc *jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#) StreamsInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#StreamsInfo().(opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) <-chan *StreamInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/StreamInfo# { |
| 1640 | return jsc.Streamsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#Streams().(opts...) |
| 1641 | } |
| 1642 | |
| 1643 | type streamNamesListerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister# struct { |
| 1644 | jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#js. *jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js# |
| 1645 | |
| 1646 | errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#err. error |
| 1647 | offsetscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#offset. int |
| 1648 | pagescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#page. []string |
| 1649 | pageInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#pageInfo. *apiPagedscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiPaged# |
| 1650 | } |
| 1651 | |
| 1652 | // Next fetches the next stream names page. |
| 1653 | func (l *streamNamesListerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#) Nextscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#Next().() bool { |
| 1654 | if l.errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#err. != nil { |
| 1655 | return false |
| 1656 | } |
| 1657 | if l.pageInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#pageInfo. != nil && l.offsetscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#offset. >= l.pageInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#pageInfo..Totalscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiPaged#Total. { |
| 1658 | return false |
| 1659 | } |
| 1660 | |
| 1661 | var cancel contextscip-go gomod github.com/golang/go/src go1.25.0 context/.CancelFuncscip-go gomod github.com/golang/go/src go1.25.0 context/CancelFunc# |
| 1662 | ctx := l.jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#js..optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts..ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx. |
| 1663 | if ctx == nil { |
| 1664 | ctx, cancel = contextscip-go gomod github.com/golang/go/src go1.25.0 context/.WithTimeoutscip-go gomod github.com/golang/go/src go1.25.0 context/WithTimeout().(contextscip-go gomod github.com/golang/go/src go1.25.0 context/.Backgroundscip-go gomod github.com/golang/go/src go1.25.0 context/Background().(), l.jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#js..optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts..waitscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#wait.) |
| 1665 | defer cancel() |
| 1666 | } |
| 1667 | |
| 1668 | req, err := jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Marshal().(streamNamesRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesRequest#{ |
| 1669 | apiPagedRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesRequest#apiPagedRequest.: apiPagedRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiPagedRequest#{Offsetscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiPagedRequest#Offset.: l.offsetscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#offset.}, |
| 1670 | Subjectscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesRequest#Subject.: l.jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#js..optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts..streamListSubjectscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#streamListSubject., |
| 1671 | }) |
| 1672 | if err != nil { |
| 1673 | l.errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#err. = err |
| 1674 | return false |
| 1675 | } |
| 1676 | r, err := l.jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#js..apiRequestWithContextscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiRequestWithContext().(ctx, l.jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#js..apiSubjscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiSubj().(apiStreamsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiStreams.), req) |
| 1677 | if err != nil { |
| 1678 | l.errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#err. = err |
| 1679 | return false |
| 1680 | } |
| 1681 | var resp streamNamesResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesResponse# |
| 1682 | if err := jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Unmarshal().(r.Datascip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Msg#Data., &resp); err != nil { |
| 1683 | l.errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#err. = err |
| 1684 | return false |
| 1685 | } |
| 1686 | if resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. != nil { |
| 1687 | l.errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#err. = resp.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. |
| 1688 | return false |
| 1689 | } |
| 1690 | |
| 1691 | l.pageInfoscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#pageInfo. = &resp.apiPagedscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesResponse#apiPaged. |
| 1692 | l.pagescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#page. = resp.Streamsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesResponse#Streams. |
| 1693 | l.offsetscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#offset. += len(l.pagescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#page.) |
| 1694 | return true |
| 1695 | } |
| 1696 | |
| 1697 | // Page returns the current ConsumerInfo page. |
| 1698 | func (l *streamNamesListerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#) Pagescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#Page().() []string { |
| 1699 | return l.pagescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#page. |
| 1700 | } |
| 1701 | |
| 1702 | // Err returns any errors found while fetching pages. |
| 1703 | func (l *streamNamesListerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#) Errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#Err().() error { |
| 1704 | return l.errscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#err. |
| 1705 | } |
| 1706 | |
| 1707 | // StreamNames is used to retrieve a list of Stream names. |
| 1708 | func (jsc *jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#) StreamNamesscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#StreamNames().(opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) <-chan string { |
| 1709 | o, cancel, err := getJSContextOptsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/getJSContextOpts().(jsc.optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts., opts...) |
| 1710 | if err != nil { |
| 1711 | return nil |
| 1712 | } |
| 1713 | |
| 1714 | ch := make(chan string) |
| 1715 | l := &streamNamesListerscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#{jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#js.: &jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#{ncscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#nc.: jsc.ncscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#nc., optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts.: o}} |
| 1716 | go func() { |
| 1717 | if cancel != nil { |
| 1718 | defer cancel() |
| 1719 | } |
| 1720 | defer close(ch) |
| 1721 | for l.Nextscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#Next().() { |
| 1722 | for _, info := range l.Pagescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesLister#Page().() { |
| 1723 | select { |
| 1724 | case ch <- info: |
| 1725 | case <-o.ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx..Donescip-go gomod github.com/golang/go/src go1.25.0 context/Context#Done().(): |
| 1726 | return |
| 1727 | } |
| 1728 | } |
| 1729 | } |
| 1730 | }() |
| 1731 | |
| 1732 | return ch |
| 1733 | } |
| 1734 | |
| 1735 | // StreamNameBySubject returns a stream name that matches the subject. |
| 1736 | func (jsc *jsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#) StreamNameBySubjectscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#StreamNameBySubject().(subj string, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) (string, error) { |
| 1737 | o, cancel, err := getJSContextOptsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/getJSContextOpts().(jsc.optsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#opts., opts...) |
| 1738 | if err != nil { |
| 1739 | return "", err |
| 1740 | } |
| 1741 | if cancel != nil { |
| 1742 | defer cancel() |
| 1743 | } |
| 1744 | |
| 1745 | var slr streamNamesResponsescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesResponse# |
| 1746 | req := &streamRequestscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamRequest#{subj} |
| 1747 | j, err := jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Marshal().(req) |
| 1748 | if err != nil { |
| 1749 | return _EMPTY_scip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/_EMPTY_., err |
| 1750 | } |
| 1751 | |
| 1752 | resp, err := jsc.apiRequestWithContextscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiRequestWithContext().(o.ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx., jsc.apiSubjscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/js#apiSubj().(apiStreamsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiStreams.), j) |
| 1753 | if err != nil { |
| 1754 | if errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Isscip-go gomod github.com/golang/go/src go1.25.0 errors/Is().(err, ErrNoRespondersscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrNoResponders.) { |
| 1755 | err = ErrJetStreamNotEnabledscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrJetStreamNotEnabled. |
| 1756 | } |
| 1757 | return _EMPTY_scip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/_EMPTY_., err |
| 1758 | } |
| 1759 | if err := jsonscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.25.0 `encoding/json`/Unmarshal().(resp.Datascip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/Msg#Data., &slr); err != nil { |
| 1760 | return _EMPTY_scip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/_EMPTY_., err |
| 1761 | } |
| 1762 | |
| 1763 | if slr.Errorscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/apiResponse#Error. != nil || len(slr.Streamsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesResponse#Streams.) != 1 { |
| 1764 | return _EMPTY_scip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/_EMPTY_., ErrNoMatchingStreamscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrNoMatchingStream. |
| 1765 | } |
| 1766 | return slr.Streamsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/streamNamesResponse#Streams.[0], nil |
| 1767 | } |
| 1768 | |
| 1769 | func getJSContextOptsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/getJSContextOpts().(defs *jsOptsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#, opts ...JSOptscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#) (*jsOptsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#, contextscip-go gomod github.com/golang/go/src go1.25.0 context/.CancelFuncscip-go gomod github.com/golang/go/src go1.25.0 context/CancelFunc#, error) { |
| 1770 | var o jsOptsscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts# |
| 1771 | for _, opt := range opts { |
| 1772 | if err := opt.configureJSContextscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/JSOpt#configureJSContext.(&o); err != nil { |
| 1773 | return nil, nil, err |
| 1774 | } |
| 1775 | } |
| 1776 | |
| 1777 | // Check for option collisions. Right now just timeout and context. |
| 1778 | if o.ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx. != nil && o.waitscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#wait. != 0 { |
| 1779 | return nil, nil, ErrContextAndTimeoutscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/ErrContextAndTimeout. |
| 1780 | } |
| 1781 | if o.waitscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#wait. == 0 && o.ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx. == nil { |
| 1782 | o.waitscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#wait. = defs.waitscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#wait. |
| 1783 | } |
| 1784 | var cancel contextscip-go gomod github.com/golang/go/src go1.25.0 context/.CancelFuncscip-go gomod github.com/golang/go/src go1.25.0 context/CancelFunc# |
| 1785 | if o.ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx. == nil && o.waitscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#wait. > 0 { |
| 1786 | o.ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx., cancel = contextscip-go gomod github.com/golang/go/src go1.25.0 context/.WithTimeoutscip-go gomod github.com/golang/go/src go1.25.0 context/WithTimeout().(contextscip-go gomod github.com/golang/go/src go1.25.0 context/.Backgroundscip-go gomod github.com/golang/go/src go1.25.0 context/Background().(), o.waitscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#wait.) |
| 1787 | } |
| 1788 | if o.prescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#pre. == _EMPTY_scip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/_EMPTY_. { |
| 1789 | o.prescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#pre. = defs.prescip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#pre. |
| 1790 | } |
| 1791 | if o.ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx. != nil { |
| 1792 | // if context does not have a deadline, use timeout from js context |
| 1793 | if _, hasDeadline := o.ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx..Deadlinescip-go gomod github.com/golang/go/src go1.25.0 context/Context#Deadline().(); !hasDeadline { |
| 1794 | o.ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx., cancel = contextscip-go gomod github.com/golang/go/src go1.25.0 context/.WithTimeoutscip-go gomod github.com/golang/go/src go1.25.0 context/WithTimeout().(o.ctxscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#ctx., defs.waitscip-go gomod github.com/nats-io/nats.go . `github.com/nats-io/nats.go`/jsOpts#wait.) |
| 1795 | } |
| 1796 | } |
| 1797 | return &o, cancel, nil |
| 1798 | } |