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 }