Skip to content

Instantly share code, notes, and snippets.

@ripienaar
Created June 14, 2024 06:02
Show Gist options
  • Save ripienaar/554b9679983bf5cba6da6a75e7ea844f to your computer and use it in GitHub Desktop.
Save ripienaar/554b9679983bf5cba6da6a75e7ea844f to your computer and use it in GitHub Desktop.
object store with domains
package main
import (
"os"
"github.com/nats-io/nats.go"
)
func main() {
nc, err := nats.Connect("nats://demo.nats.io")
if err != nil {
panic(err)
}
js, err := nc.JetStream(nats.Domain("DEVCO"))
if err != nil {
panic(err)
}
bucket, err := js.ObjectStore("X")
if err != nil {
panic(err)
}
f, err := os.Open("x")
if err != nil {
panic(err)
}
_, err = bucket.Put(&nats.ObjectMeta{Name: "X"}, f)
if err != nil {
panic(err)
}
return
}
package main
import (
"context"
"os"
"github.com/nats-io/nats.go"
"github.com/nats-io/nats.go/jetstream"
)
func main() {
nc, err := nats.Connect("nats://demo.nats.io")
if err != nil {
panic(err)
}
js, err := jetstream.NewWithDomain(nc, "DEVCO")
if err != nil {
panic(err)
}
bucket, err := js.ObjectStore(context.TODO(), "X")
if err != nil {
panic(err)
}
f, err := os.Open("x")
if err != nil {
panic(err)
}
_, err = bucket.Put(context.TODO(), jetstream.ObjectMeta{Name: "X"}, f)
if err != nil {
panic(err)
}
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment