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

Method UpdateStream

jsm.go:1118–1171  ·  view source on GitHub ↗

UpdateStream updates a Stream.

(cfg *StreamConfig, opts ...JSOpt)

Source from the content-addressed store, hash-verified

1116
1117// UpdateStream updates a Stream.
1118func (js *js) UpdateStream(cfg *StreamConfig, opts ...JSOpt) (*StreamInfo, error) {
1119 if cfg == nil {
1120 return nil, ErrStreamConfigRequired
1121 }
1122 if err := checkStreamName(cfg.Name); err != nil {
1123 return nil, err
1124 }
1125 o, cancel, err := getJSContextOpts(js.opts, opts...)
1126 if err != nil {
1127 return nil, err
1128 }
1129 if cancel != nil {
1130 defer cancel()
1131 }
1132
1133 req, err := json.Marshal(cfg)
1134 if err != nil {
1135 return nil, err
1136 }
1137
1138 usSubj := js.apiSubj(fmt.Sprintf(apiStreamUpdateT, cfg.Name))
1139 r, err := js.apiRequestWithContext(o.ctx, usSubj, req)
1140 if err != nil {
1141 return nil, err
1142 }
1143 var resp streamInfoResponse
1144 if err := json.Unmarshal(r.Data, &resp); err != nil {
1145 return nil, err
1146 }
1147 if resp.Error != nil {
1148 if errors.Is(resp.Error, ErrStreamNotFound) {
1149 return nil, ErrStreamNotFound
1150 }
1151 return nil, resp.Error
1152 }
1153
1154 // check that input subject transform (if used) is reflected in the returned StreamInfo
1155 if cfg.SubjectTransform != nil && resp.StreamInfo.Config.SubjectTransform == nil {
1156 return nil, ErrStreamSubjectTransformNotSupported
1157 }
1158
1159 if len(cfg.Sources) != 0 {
1160 if len(cfg.Sources) != len(resp.Config.Sources) {
1161 return nil, ErrStreamSourceNotSupported
1162 }
1163 for i := range cfg.Sources {
1164 if len(cfg.Sources[i].SubjectTransforms) != 0 && len(resp.Sources[i].SubjectTransforms) == 0 {
1165 return nil, ErrStreamSourceMultipleSubjectTransformsNotSupported
1166 }
1167 }
1168 }
1169
1170 return resp.StreamInfo, nil
1171}
1172
1173// streamDeleteResponse is the response for a Stream delete request.
1174type streamDeleteResponse struct {

Callers 1

CreateKeyValueMethod · 0.95

Calls 5

apiSubjMethod · 0.95
apiRequestWithContextMethod · 0.95
checkStreamNameFunction · 0.85
getJSContextOptsFunction · 0.85
IsMethod · 0.45

Tested by

no test coverage detected