feat: working version
1. implemented filesystem storage, NATS object storage and saving to Vault. 2. Test coverage is fine for filesystem and Vault (and NATS object does not really require extensive tests)
This commit is contained in:
36
storageutil/nats.go
Normal file
36
storageutil/nats.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package storageutil
|
||||
|
||||
import "github.com/nats-io/nats.go"
|
||||
|
||||
// CreateNatsObjectStore is a convenience function that
|
||||
// connects to NATS and using provided url and creates
|
||||
// new object store using bucket as bucket name.
|
||||
// The object store uses NATS file storage and compression.
|
||||
// If fine-tuning is required - just create the store in your
|
||||
// code and pass it to the storage package.
|
||||
func CreateNatsObjectStore(url string, bucket string) (nats.ObjectStore, *nats.Conn, error) {
|
||||
nc, err := nats.Connect(url)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
js, err := nc.JetStream()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
cfg := &nats.ObjectStoreConfig{
|
||||
Bucket: bucket,
|
||||
Description: "tiny storage bucket",
|
||||
MaxBytes: -1,
|
||||
Storage: nats.FileStorage,
|
||||
Compression: true,
|
||||
}
|
||||
|
||||
store, err := js.CreateObjectStore(cfg)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return store, nc, nil
|
||||
}
|
Reference in New Issue
Block a user