@@ -12,7 +12,7 @@ title: Nats
12
12
13
13
A NATS Key/Value storage driver.
14
14
15
- ** Note: Requires Go 1.20 and above**
15
+ ## Note: Requires Go 1.20 and above
16
16
17
17
### Table of Contents
18
18
@@ -57,60 +57,56 @@ Import the storage package.
57
57
import "github.com/gofiber/storage/nats"
58
58
```
59
59
60
- You can use the following possibilities to create a storage:
60
+ You can use the following options to create a storage driver :
61
61
62
62
```go
63
63
// Initialize default config
64
64
store := nats.New()
65
65
66
66
// Initialize custom config
67
67
store := nats.New(Config{
68
- URLs: " nats://127.0.0.1:4443" ,
69
- NatsOptions: []nats.Option {
70
- nats.MaxReconnects (2 ),
71
- // Enable TLS by specifying RootCAs
72
- nats.RootCAs (" ./testdata/certs/ca.pem" ),
73
- },
74
- KeyValueConfig: jetstream.KeyValueConfig {
75
- Bucket: " test" ,
76
- Storage: jetstream.MemoryStorage ,
77
- },
68
+ URLs: " nats://127.0.0.1:4443" ,
69
+ NatsOptions: []nats.Option {
70
+ nats.MaxReconnects (2 ),
71
+ // Enable TLS by specifying RootCAs
72
+ nats.RootCAs (" ./testdata/certs/ca.pem" ),
73
+ },
74
+ KeyValueConfig: jetstream.KeyValueConfig {
75
+ Bucket: " test" ,
76
+ Storage: jetstream.MemoryStorage ,
77
+ },
78
78
})
79
79
```
80
80
81
81
### Config
82
82
83
83
``` go
84
84
type Config struct {
85
- // Nats URLs, default "nats://127.0.0.1:4222". Can be comma separated list for multiple servers
86
- URLs string
87
- // Nats connection options. See nats_test.go for an example of how to use this.
88
- NatsOptions []nats.Option
89
- // Nats connection name
90
- ClientName string
91
- // Nats context
92
- Context context.Context
93
- // Nats key value config
94
- KeyValueConfig jetstream.KeyValueConfig
95
- // Logger. Using Fiber AllLogger interface for adapting the various log libraries.
96
- Logger log.AllLogger
97
- // Use the Logger for nats events, default: false
98
- Verbose bool
99
- // Wait for connection to be established, default: 100ms
100
- WaitForConnection time.Duration
85
+ // Nats URLs, default "nats://127.0.0.1:4222". Can be comma separated list for multiple servers
86
+ URLs string
87
+ // Nats connection options. See nats_test.go for an example of how to use this.
88
+ NatsOptions []nats.Option
89
+ // Nats connection name
90
+ ClientName string
91
+ // Nats context
92
+ Context context.Context
93
+ // Nats key value config
94
+ KeyValueConfig jetstream.KeyValueConfig
95
+ // Wait for connection to be established, default: 100ms
96
+ WaitForConnection time.Duration
101
97
}
102
98
```
103
99
104
100
### Default Config
105
101
106
102
``` go
107
103
var ConfigDefault = Config {
108
- URLs : nats.DefaultURL ,
109
- Context : context.Background (),
110
- ClientName : " fiber_storage" ,
111
- KeyValueConfig : jetstream.KeyValueConfig {
112
- Bucket: " fiber_storage" ,
113
- },
114
- WaitForConnection : 100 * time.Millisecond ,
104
+ URLs : nats.DefaultURL ,
105
+ Context : context.Background (),
106
+ ClientName : " fiber_storage" ,
107
+ KeyValueConfig : jetstream.KeyValueConfig {
108
+ Bucket: " fiber_storage" ,
109
+ },
110
+ WaitForConnection : 100 * time.Millisecond ,
115
111
}
116
112
```
0 commit comments