KeyValue will lookup and bind to an existing KeyValue store.
(bucket string)
| 372 | |
| 373 | // KeyValue will lookup and bind to an existing KeyValue store. |
| 374 | func (js *js) KeyValue(bucket string) (KeyValue, error) { |
| 375 | if !js.nc.serverMinVersion(2, 6, 2) { |
| 376 | return nil, errors.New("nats: key-value requires at least server version 2.6.2") |
| 377 | } |
| 378 | if !bucketValid(bucket) { |
| 379 | return nil, ErrInvalidBucketName |
| 380 | } |
| 381 | stream := fmt.Sprintf(kvBucketNameTmpl, bucket) |
| 382 | si, err := js.StreamInfo(stream) |
| 383 | if err != nil { |
| 384 | if errors.Is(err, ErrStreamNotFound) { |
| 385 | err = ErrBucketNotFound |
| 386 | } |
| 387 | return nil, err |
| 388 | } |
| 389 | // Do some quick sanity checks that this is a correctly formed stream for KV. |
| 390 | // Max msgs per subject should be > 0. |
| 391 | if si.Config.MaxMsgsPerSubject < 1 { |
| 392 | return nil, ErrBadBucket |
| 393 | } |
| 394 | |
| 395 | return mapStreamToKVS(js, si), nil |
| 396 | } |
| 397 | |
| 398 | // CreateKeyValue will create a KeyValue store with the following configuration. |
| 399 | func (js *js) CreateKeyValue(cfg *KeyValueConfig) (KeyValue, error) { |
nothing calls this directly
no test coverage detected