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

Method StreamInfo

jsm.go:973–1049  ·  view source on GitHub ↗
(stream string, opts ...JSOpt)

Source from the content-addressed store, hash-verified

971)
972
973func (js *js) StreamInfo(stream string, opts ...JSOpt) (*StreamInfo, error) {
974 if err := checkStreamName(stream); err != nil {
975 return nil, err
976 }
977 o, cancel, err := getJSContextOpts(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 StreamInfoRequest
991 if o.streamInfoOpts != nil {
992 requestPayload = true
993 siOpts = *o.streamInfoOpts
994 }
995
996 for {
997 if requestPayload {
998 siOpts.Offset = i
999 if req, err = json.Marshal(&siOpts); err != nil {
1000 return nil, err
1001 }
1002 }
1003
1004 siSubj := js.apiSubj(fmt.Sprintf(apiStreamInfoT, stream))
1005
1006 r, err := js.apiRequestWithContext(o.ctx, siSubj, req)
1007 if err != nil {
1008 return nil, err
1009 }
1010
1011 var resp streamInfoResponse
1012 if err := json.Unmarshal(r.Data, &resp); err != nil {
1013 return nil, err
1014 }
1015
1016 if resp.Error != nil {
1017 if errors.Is(resp.Error, ErrStreamNotFound) {
1018 return nil, ErrStreamNotFound
1019 }
1020 return nil, resp.Error
1021 }
1022
1023 var total int
1024 // for backwards compatibility
1025 if resp.Total != 0 {
1026 total = resp.Total
1027 } else {
1028 total = len(resp.State.Subjects)
1029 }
1030

Callers 3

KeyValueMethod · 0.95
CreateKeyValueMethod · 0.95
ObjectStoreMethod · 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