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:
2025-07-27 19:02:05 +03:00
parent 854de3865b
commit 48878e8433
13 changed files with 265 additions and 153 deletions

36
storageutil/nats.go Normal file
View 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
}