-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.go
74 lines (60 loc) · 1.3 KB
/
module.go
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
72
73
74
package certmagic_nats
import (
"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
"github.com/caddyserver/certmagic"
)
var (
_ caddy.StorageConverter = (*Nats)(nil)
_ caddyfile.Unmarshaler = (*Nats)(nil)
)
func init() {
caddy.RegisterModule(Nats{})
}
func (n *Nats) Provision(ctx caddy.Context) error {
n.logger = ctx.Logger(n)
if n.InboxPrefix == "" {
n.InboxPrefix = "_INBOX"
}
kv, err := connectNats(n.Hosts, n.Creds, n.Bucket, n.ConnectionName, n.InboxPrefix)
if err != nil {
return err
}
n.revMap = make(map[string]uint64)
n.Client = kv
return nil
}
func (n *Nats) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
for d.Next() {
var value string
key := d.Val()
if !d.Args(&value) {
continue
}
switch key {
case "hosts":
n.Hosts = value
case "bucket":
n.Bucket = value
case "creds":
n.Creds = value
case "inbox_prefix":
n.InboxPrefix = value
case "connection_name":
n.ConnectionName = value
}
}
return nil
}
func (Nats) CaddyModule() caddy.ModuleInfo {
return caddy.ModuleInfo{
ID: "caddy.storage.nats",
New: func() caddy.Module {
return &Nats{}
},
}
}
// CertMagicStorage converts s to a certmagic.Storage instance.
func (n *Nats) CertMagicStorage() (certmagic.Storage, error) {
return n, nil
}