-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcaddy.go
65 lines (58 loc) · 1.4 KB
/
caddy.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
package dynamodbstorage
import (
"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
"github.com/caddyserver/certmagic"
)
func init() {
caddy.RegisterModule(Storage{})
}
// CaddyModule returns the Caddy module information.
func (Storage) CaddyModule() caddy.ModuleInfo {
return caddy.ModuleInfo{
ID: "caddy.storage.dynamodb",
New: func() caddy.Module { return new(Storage) },
}
}
// CertMagicStorage converts s to a certmagic.Storage instance.
func (s *Storage) CertMagicStorage() (certmagic.Storage, error) {
return s, nil
}
// UnmarshalCaddyfile sets up the storage module from Caddyfile tokens. Syntax:
//
// dynamodb <table_name> {
// aws_endpoint <endpoint>
// aws_region <region>
// }
//
// Only the table name is required.
func (s *Storage) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
for d.Next() {
if !d.NextArg() {
return d.ArgErr()
}
s.Table = d.Val()
for nesting := d.Nesting(); d.NextBlock(nesting); {
switch d.Val() {
case "aws_endpoint":
if !d.NextArg() {
return d.ArgErr()
}
s.AwsEndpoint = d.Val()
case "aws_region":
if !d.NextArg() {
return d.ArgErr()
}
s.AwsRegion = d.Val()
default:
return d.Errf("unrecognized parameter '%s'", d.Val())
}
}
}
return nil
}
// Interface guards
var (
_ caddy.StorageConverter = (*Storage)(nil)
_ caddyfile.Unmarshaler = (*Storage)(nil)
)