31 lines
592 B
Go
31 lines
592 B
Go
package natskv
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.optclblast.xyz/draincloud/draincloud-core/internal/logger"
|
|
"github.com/nats-io/nats.go/jetstream"
|
|
)
|
|
|
|
type Provider struct {
|
|
cc jetstream.KeyValue
|
|
}
|
|
|
|
func New(
|
|
ctx context.Context,
|
|
js jetstream.JetStream,
|
|
) *Provider {
|
|
kv, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{
|
|
Bucket: "rtc",
|
|
Description: "Real Time Config",
|
|
Storage: jetstream.FileStorage,
|
|
Replicas: 2,
|
|
Compression: true,
|
|
})
|
|
if err != nil {
|
|
logger.Fatal(ctx, "[natskv][New] failed to initialize rtc", logger.Err(err))
|
|
}
|
|
|
|
return &Provider{cc: kv}
|
|
}
|