Stream fetches [StreamInfo] and returns a [Stream] interface for a given stream name. If stream does not exist, ErrStreamNotFound is returned.
(ctx context.Context, name string)
| 798 | // Stream fetches [StreamInfo] and returns a [Stream] interface for a given stream name. |
| 799 | // If stream does not exist, ErrStreamNotFound is returned. |
| 800 | func (js *jetStream) Stream(ctx context.Context, name string) (Stream, error) { |
| 801 | if err := validateStreamName(name); err != nil { |
| 802 | return nil, err |
| 803 | } |
| 804 | ctx, cancel := js.wrapContextWithoutDeadline(ctx) |
| 805 | if cancel != nil { |
| 806 | defer cancel() |
| 807 | } |
| 808 | infoSubject := fmt.Sprintf(apiStreamInfoT, name) |
| 809 | |
| 810 | var resp streamInfoResponse |
| 811 | |
| 812 | if _, err := js.apiRequestJSON(ctx, infoSubject, &resp); err != nil { |
| 813 | return nil, err |
| 814 | } |
| 815 | if resp.Error != nil { |
| 816 | if resp.Error.ErrorCode == JSErrCodeStreamNotFound { |
| 817 | return nil, ErrStreamNotFound |
| 818 | } |
| 819 | return nil, resp.Error |
| 820 | } |
| 821 | return &stream{ |
| 822 | js: js, |
| 823 | name: name, |
| 824 | info: resp.StreamInfo, |
| 825 | }, nil |
| 826 | } |
| 827 | |
| 828 | // DeleteStream removes a stream with given name |
| 829 | func (js *jetStream) DeleteStream(ctx context.Context, name string) error { |
no test coverage detected