From 200b836b6b62a2613f1cc90e74f005e727710dc5 Mon Sep 17 00:00:00 2001 From: jnmoyne Date: Tue, 13 Sep 2022 14:40:50 -0700 Subject: [PATCH] from ...string to ...JSOpt --- js_test.go | 2 +- jsm.go | 28 ++++++++++++---------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/js_test.go b/js_test.go index 2c3b9c019..14460d1fc 100644 --- a/js_test.go +++ b/js_test.go @@ -1120,7 +1120,7 @@ func TestJetStreamStreamInfoSubjectDetails(t *testing.T) { nc.Publish(fmt.Sprintf("test.%d", i), payload) } - result, err := js.StreamContainedSubjects("TEST", "test.*") + result, err := js.StreamContainedSubjects("TEST", &StreamInfoRequest{SubjectsFilter: "test.*"}) if err != nil { t.Fatalf("Unexpected error: %v", err) } diff --git a/jsm.go b/jsm.go index 7a8a93690..229b20fe6 100644 --- a/jsm.go +++ b/jsm.go @@ -38,7 +38,7 @@ type JetStreamManager interface { StreamInfo(stream string, opts ...JSOpt) (*StreamInfo, error) // StreamContainedSubjects queries the stream for the subjects it holds with optional filter - StreamContainedSubjects(stream string, filter ...string) (map[string]uint64, error) + StreamContainedSubjects(stream string, opts ...JSOpt) (map[string]uint64, error) // PurgeStream purges a stream messages. PurgeStream(name string, opts ...JSOpt) error @@ -735,35 +735,31 @@ func (js *js) StreamInfo(stream string, opts ...JSOpt) (*StreamInfo, error) { return resp.StreamInfo, nil } -func (js *js) StreamContainedSubjects(stream string, filter ...string) (map[string]uint64, error) { +func (js *js) StreamContainedSubjects(stream string, opts ...JSOpt) (map[string]uint64, error) { if err := checkStreamName(stream); err != nil { return nil, err } - - if len(filter) > 1 { - return nil, fmt.Errorf("only 1 filter supported") + o, cancel, err := getJSContextOpts(js.opts, opts...) + if err != nil { + return nil, err } - - f := ">" - if len(filter) == 1 && filter[0] != "" { - f = filter[0] + if cancel != nil { + defer cancel() } var i int var subjectMessagesMap map[string]uint64 = nil - o, cancel, err := getJSContextOpts(js.opts) - if err != nil { - return nil, err - } - if cancel != nil { - defer cancel() + if o.streamInfoOpts != nil && o.streamInfoOpts.SubjectsFilter == _EMPTY_ { + o.streamInfoOpts.SubjectsFilter = ">" } for { var req []byte - if req, err = json.Marshal(StreamInfoRequest{SubjectsFilter: f, apiPagedRequest: apiPagedRequest{Offset: i}}); err != nil { + o.streamInfoOpts.Offset = i + + if req, err = json.Marshal(o.streamInfoOpts); err != nil { return nil, err }