-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.go
More file actions
71 lines (60 loc) · 1.36 KB
/
options.go
File metadata and controls
71 lines (60 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package mini
import "github.com/nats-io/nats.go"
type Options struct {
Bucket string
Key string
NatsUrl string
NatsOptions []nats.Option
LogLevel string
Endpoints []EndpointInitializer
ConfigWatched bool
}
type Option func(*Options) error
func WithBucket(bucket string) Option {
return func(o *Options) error {
o.Bucket = bucket
return nil
}
}
func WithConfigWatched() Option {
return func(o *Options) error {
o.ConfigWatched = true
return nil
}
}
func WithLogLevel(level string) Option {
return func(o *Options) error {
o.LogLevel = level
return nil
}
}
func WithNatsUrl(url string) Option {
return func(o *Options) error {
o.NatsUrl = url
return nil
}
}
func WithEndpoints(endpoints ...EndpointInitializer) Option {
return func(o *Options) error {
o.Endpoints = append(o.Endpoints, endpoints...)
return nil
}
}
func WithKey(key string) Option {
return func(o *Options) error {
o.Key = key
return nil
}
}
func WithCredentials(jwt string, seed string) Option {
return func(o *Options) error {
o.NatsOptions = append(o.NatsOptions, nats.UserJWTAndSeed(jwt, seed))
return nil
}
}
func WithCredentialsFile(file string) Option {
return func(o *Options) error {
o.NatsOptions = append(o.NatsOptions, nats.UserCredentials(file))
return nil
}
}