Skip to content

Commit 31c56c3

Browse files
committed
initial
Signed-off-by: jkoberg <[email protected]>
1 parent 185a524 commit 31c56c3

File tree

12 files changed

+1702
-5
lines changed

12 files changed

+1702
-5
lines changed

Diff for: .golangci.yaml

+6-4
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,11 @@ linters-settings:
111111
# minimal occurrences count to trigger, 3 by default
112112
min-occurrences: 3
113113
depguard:
114-
list-type: blacklist
115-
# Packages listed here will reported as error if imported
116-
packages:
117-
- github.com/golang/protobuf/proto
114+
rules:
115+
main:
116+
deny:
117+
- pkg: "github.com/golang/protobuf/proto"
118+
desc: not allowed
118119
misspell:
119120
# Correct spellings using locale preferences for US or UK.
120121
# Default is to use a neutral variety of English.
@@ -231,6 +232,7 @@ issues:
231232
- funlen
232233
- varnamelen
233234
- wsl
235+
- forbidigo
234236

235237
# Independently from option `exclude` we use default exclude patterns,
236238
# it can be disabled by this option. To list all

Diff for: go.work

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
go 1.18
1+
go 1.21
22

33
use (
44
./v4/acme/certmagic
@@ -84,6 +84,7 @@ use (
8484
./v4/store/memory
8585
./v4/store/mysql
8686
./v4/store/nats-js
87+
./v4/store/nats-js-kv
8788
./v4/store/redis
8889
./v4/sync/consul
8990
./v4/sync/etcd

Diff for: v4/store/nats-js-kv/README.md

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# NATS JetStream Store Plugin
2+
3+
> **WARNING**: NATS Object Storage is still marked as an experimental preview.
4+
5+
This plugin uses the NATS JetStream [Object Store](https://docs.nats.io/nats-concepts/jetstream/obj_store) to implement the Go-Micro store interface.
6+
7+
This enables a key/value store with unlimited message size, allowing you to store files or data of any size under a single key.
8+
9+
You can use this plugin like any other store plugin.
10+
To start a local NATS JetStream server run `nats-server -js`.
11+
12+
To manually create a new storage object call:
13+
14+
```go
15+
natsjs.NewStore(opts ...store.Option)
16+
```
17+
18+
The Go-Micro store interface uses databases and tables to store keys. These translate
19+
to buckets (object stores) and key prefixes. If no database (bucket name) is provided, "default" will be used.
20+
21+
You can call `Write` with any arbitrary database name, and if a bucket with that name does not exist yet,
22+
it will be automatically created.
23+
24+
If a table name is provided, it will use it to prefix the key as `<table>_<key>`.
25+
26+
To delete a bucket, and all the key/value pairs in it, pass the `DeleteBucket` option to the `Delete`
27+
method, then they key name will be interpreted as a bucket name, and the bucket will be deleted.
28+
29+
Next to the default store options, a few NATS specific options are available:
30+
31+
32+
```go
33+
// NatsOptions accepts nats.Options
34+
NatsOptions(opts nats.Options)
35+
36+
// JetStreamOptions accepts multiple nats.JSOpt
37+
JetStreamOptions(opts ...nats.JSOpt)
38+
39+
// ObjectStoreOptions accepts multiple nats.ObjectStoreConfigs
40+
// This will create buckets with the provided configs at initialization.
41+
//
42+
// type ObjectStoreConfig struct {
43+
// Bucket string
44+
// Description string
45+
// TTL time.Duration
46+
// MaxBytes int64
47+
// Storage StorageType (either memory or file storage)
48+
// Replicas int
49+
// Placement *Placement
50+
// }
51+
//
52+
ObjectStoreOptions(cfg ...*nats.ObjectStoreConfig)
53+
54+
// DefaultTTL sets the default TTL to use for new buckets
55+
// By default no TTL is set.
56+
//
57+
// TTL ON INDIVIDUAL WRITE CALLS IS NOT SUPPORTED, only bucket wide TTL.
58+
// Either set a default TTL with this option or provide bucket specific options
59+
// with ObjectStoreOptions
60+
DefaultTTL(ttl time.Duration)
61+
62+
// DefaultMemory sets the default storage type to memory only.
63+
//
64+
// The default is file storage, persisting storage between service restarts.
65+
// Be aware that the default storage location of NATS the /tmp dir is, and thus
66+
// won't persist reboots.
67+
DefaultMemory()
68+
69+
// DefaultDescription sets the default description to use when creating new
70+
// buckets. The default is "Store managed by go-micro"
71+
DefaultDescription(text string)
72+
73+
// DeleteBucket will use the key passed to Delete as a bucket (database) name,
74+
// and delete the bucket.
75+
// This option should not be combined with the store.DeleteFrom option, as
76+
// that will overwrite the delete action.
77+
DeleteBucket()
78+
```
79+

Diff for: v4/store/nats-js-kv/context.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package natsjskv
2+
3+
import (
4+
"context"
5+
6+
"go-micro.dev/v4/store"
7+
)
8+
9+
// setStoreOption returns a function to setup a context with given value.
10+
func setStoreOption(k, v interface{}) store.Option {
11+
return func(o *store.Options) {
12+
if o.Context == nil {
13+
o.Context = context.Background()
14+
}
15+
16+
o.Context = context.WithValue(o.Context, k, v)
17+
}
18+
}

Diff for: v4/store/nats-js-kv/go.mod

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
module github.com/go-micro/plugins/v4/store/nats-js-kv
2+
3+
go 1.21
4+
5+
require (
6+
github.com/cornelk/hashmap v1.0.8
7+
github.com/nats-io/nats-server/v2 v2.8.4
8+
)
9+
10+
require (
11+
github.com/Microsoft/go-winio v0.5.2 // indirect
12+
github.com/ProtonMail/go-crypto v0.0.0-20220824120805-4b6e5c587895 // indirect
13+
github.com/acomagu/bufpipe v1.0.3 // indirect
14+
github.com/bitly/go-simplejson v0.5.0 // indirect
15+
github.com/cloudflare/circl v1.2.0 // indirect
16+
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
17+
github.com/davecgh/go-spew v1.1.1 // indirect
18+
github.com/emirpasic/gods v1.18.1 // indirect
19+
github.com/fsnotify/fsnotify v1.5.4 // indirect
20+
github.com/go-git/gcfg v1.5.0 // indirect
21+
github.com/go-git/go-billy/v5 v5.3.1 // indirect
22+
github.com/go-git/go-git/v5 v5.4.2 // indirect
23+
github.com/golang/protobuf v1.5.2 // indirect
24+
github.com/google/go-cmp v0.5.6 // indirect
25+
github.com/imdario/mergo v0.3.13 // indirect
26+
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
27+
github.com/kevinburke/ssh_config v1.2.0 // indirect
28+
github.com/klauspost/compress v1.17.0 // indirect
29+
github.com/minio/highwayhash v1.0.2 // indirect
30+
github.com/mitchellh/go-homedir v1.1.0 // indirect
31+
github.com/nats-io/jwt/v2 v2.2.1-0.20220330180145-442af02fd36a // indirect
32+
github.com/nats-io/nkeys v0.4.5 // indirect
33+
github.com/nats-io/nuid v1.0.1 // indirect
34+
github.com/nxadm/tail v1.4.8 // indirect
35+
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
36+
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
37+
github.com/pmezard/go-difflib v1.0.0 // indirect
38+
github.com/russross/blackfriday/v2 v2.1.0 // indirect
39+
github.com/sergi/go-diff v1.2.0 // indirect
40+
github.com/test-go/testify v1.1.4 // indirect
41+
github.com/urfave/cli/v2 v2.14.0 // indirect
42+
github.com/xanzy/ssh-agent v0.3.2 // indirect
43+
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
44+
golang.org/x/mod v0.8.0 // indirect
45+
golang.org/x/sys v0.5.0 // indirect
46+
golang.org/x/text v0.13.0 // indirect
47+
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 // indirect
48+
golang.org/x/tools v0.6.0 // indirect
49+
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
50+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
51+
gopkg.in/warnings.v0 v0.1.2 // indirect
52+
gopkg.in/yaml.v3 v3.0.1 // indirect
53+
)
54+
55+
require (
56+
github.com/google/uuid v1.3.0
57+
github.com/miekg/dns v1.1.50 // indirect
58+
github.com/nats-io/nats.go v1.31.0
59+
github.com/pkg/errors v0.9.1
60+
github.com/stretchr/testify v1.7.1
61+
go-micro.dev/v4 v4.9.0
62+
golang.org/x/crypto v0.6.0 // indirect
63+
golang.org/x/net v0.6.0 // indirect
64+
golang.org/x/sync v0.1.0 // indirect
65+
google.golang.org/protobuf v1.28.1 // indirect
66+
)

0 commit comments

Comments
 (0)