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

Method GetInfo

jetstream/object.go:1160–1195  ·  view source on GitHub ↗

GetInfo will retrieve the current information for the object.

(ctx context.Context, name string, opts ...GetObjectInfoOpt)

Source from the content-addressed store, hash-verified

1158
1159// GetInfo will retrieve the current information for the object.
1160func (obs *obs) GetInfo(ctx context.Context, name string, opts ...GetObjectInfoOpt) (*ObjectInfo, error) {
1161 // Grab last meta value we have.
1162 if name == "" {
1163 return nil, ErrNameRequired
1164 }
1165 var o getObjectInfoOpts
1166 for _, opt := range opts {
1167 if opt != nil {
1168 if err := opt(&o); err != nil {
1169 return nil, err
1170 }
1171 }
1172 }
1173
1174 metaSubj := fmt.Sprintf(objMetaPreTmpl, obs.name, encodeName(name)) // used as data in a JS API call
1175
1176 m, err := obs.stream.GetLastMsgForSubject(ctx, metaSubj)
1177 if err != nil {
1178 if errors.Is(err, ErrMsgNotFound) {
1179 err = ErrObjectNotFound
1180 }
1181 if errors.Is(err, ErrStreamNotFound) {
1182 err = ErrBucketNotFound
1183 }
1184 return nil, err
1185 }
1186 var info ObjectInfo
1187 if err := json.Unmarshal(m.Data, &info); err != nil {
1188 return nil, ErrBadObjectMeta
1189 }
1190 if !o.showDeleted && info.Deleted {
1191 return nil, ErrObjectNotFound
1192 }
1193 info.ModTime = m.Time
1194 return &info, nil
1195}
1196
1197// UpdateMeta will update the meta for the object.
1198func (obs *obs) UpdateMeta(ctx context.Context, name string, meta ObjectMeta) error {

Callers 6

PutMethod · 0.95
GetMethod · 0.95
DeleteMethod · 0.95
AddLinkMethod · 0.95
AddBucketLinkMethod · 0.95
UpdateMetaMethod · 0.95

Calls 3

encodeNameFunction · 0.70
GetLastMsgForSubjectMethod · 0.65
IsMethod · 0.45

Tested by

no test coverage detected