summaryrefslogtreecommitdiff
path: root/caddyconfig
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-09-19 12:42:36 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2019-09-19 12:42:36 -0600
commitba29f9d41d7951bde07dc2e0d6a1471c40bb7145 (patch)
tree1a76ab0796e57a31bf8fc36ff4bb34779215edb7 /caddyconfig
parent40e05e5a01d50b381fa7a7a472ea38f44518f02c (diff)
httpcaddyfile: Global storage configuration (closes #2758)
Diffstat (limited to 'caddyconfig')
-rw-r--r--caddyconfig/httpcaddyfile/httptype.go14
-rw-r--r--caddyconfig/httpcaddyfile/options.go38
2 files changed, 44 insertions, 8 deletions
diff --git a/caddyconfig/httpcaddyfile/httptype.go b/caddyconfig/httpcaddyfile/httptype.go
index 6b2ee6b..ff340de 100644
--- a/caddyconfig/httpcaddyfile/httptype.go
+++ b/caddyconfig/httpcaddyfile/httptype.go
@@ -57,15 +57,18 @@ func (st ServerType) Setup(originalServerBlocks []caddyfile.ServerBlock,
dir := segment.Directive()
var val interface{}
var err error
+ disp := caddyfile.NewDispenser(segment)
switch dir {
case "http_port":
- val, err = parseHTTPPort(caddyfile.NewDispenser(segment))
+ val, err = parseOptHTTPPort(disp)
case "https_port":
- val, err = parseHTTPSPort(caddyfile.NewDispenser(segment))
+ val, err = parseOptHTTPSPort(disp)
case "handler_order":
- val, err = parseHandlerOrder(caddyfile.NewDispenser(segment))
+ val, err = parseOptHandlerOrder(disp)
case "experimental_http3":
- val, err = parseExperimentalHTTP3(caddyfile.NewDispenser(segment))
+ val, err = parseOptExperimentalHTTP3(disp)
+ case "storage":
+ val, err = parseOptStorage(disp)
default:
return nil, warnings, fmt.Errorf("unrecognized parameter name: %s", dir)
}
@@ -207,6 +210,9 @@ func (st ServerType) Setup(originalServerBlocks []caddyfile.ServerBlock,
if !reflect.DeepEqual(tlsApp, caddytls.TLS{}) {
cfg.AppsRaw["tls"] = caddyconfig.JSON(tlsApp, &warnings)
}
+ if storageCvtr, ok := options["storage"].(caddy.StorageConverter); ok {
+ cfg.StorageRaw = caddyconfig.JSON(storageCvtr, &warnings)
+ }
return cfg, warnings, nil
}
diff --git a/caddyconfig/httpcaddyfile/options.go b/caddyconfig/httpcaddyfile/options.go
index 1d7864c..dadde28 100644
--- a/caddyconfig/httpcaddyfile/options.go
+++ b/caddyconfig/httpcaddyfile/options.go
@@ -15,12 +15,14 @@
package httpcaddyfile
import (
+ "fmt"
"strconv"
+ "github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
)
-func parseHTTPPort(d *caddyfile.Dispenser) (int, error) {
+func parseOptHTTPPort(d *caddyfile.Dispenser) (int, error) {
var httpPort int
for d.Next() {
var httpPortStr string
@@ -36,7 +38,7 @@ func parseHTTPPort(d *caddyfile.Dispenser) (int, error) {
return httpPort, nil
}
-func parseHTTPSPort(d *caddyfile.Dispenser) (int, error) {
+func parseOptHTTPSPort(d *caddyfile.Dispenser) (int, error) {
var httpsPort int
for d.Next() {
var httpsPortStr string
@@ -52,11 +54,11 @@ func parseHTTPSPort(d *caddyfile.Dispenser) (int, error) {
return httpsPort, nil
}
-func parseExperimentalHTTP3(d *caddyfile.Dispenser) (bool, error) {
+func parseOptExperimentalHTTP3(d *caddyfile.Dispenser) (bool, error) {
return true, nil
}
-func parseHandlerOrder(d *caddyfile.Dispenser) ([]string, error) {
+func parseOptHandlerOrder(d *caddyfile.Dispenser) ([]string, error) {
if !d.Next() {
return nil, d.ArgErr()
}
@@ -78,3 +80,31 @@ func parseHandlerOrder(d *caddyfile.Dispenser) ([]string, error) {
}
return order, nil
}
+
+func parseOptStorage(d *caddyfile.Dispenser) (caddy.StorageConverter, error) {
+ if !d.Next() {
+ return nil, d.ArgErr()
+ }
+ args := d.RemainingArgs()
+ if len(args) != 1 {
+ return nil, d.ArgErr()
+ }
+ modName := args[0]
+ mod, err := caddy.GetModule("caddy.storage." + modName)
+ if err != nil {
+ return nil, fmt.Errorf("getting storage module '%s': %v", modName, err)
+ }
+ unm, ok := mod.New().(caddyfile.Unmarshaler)
+ if !ok {
+ return nil, fmt.Errorf("storage module '%s' is not a Caddyfile unmarshaler", mod.Name)
+ }
+ err = unm.UnmarshalCaddyfile(d.NewFromNextTokens())
+ if err != nil {
+ return nil, err
+ }
+ storage, ok := unm.(caddy.StorageConverter)
+ if !ok {
+ return nil, fmt.Errorf("module %s is not a StorageConverter", mod.Name)
+ }
+ return storage, nil
+}