diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2019-08-22 13:38:37 -0600 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2019-08-22 13:38:37 -0600 |
commit | af25f0254e94eb2e2898ba495bfc3de209a49e79 (patch) | |
tree | 79f20651d4fcdb27fe5c3299892576d38e82badb /caddyconfig/caddyfile | |
parent | a0fd2b6c0abbd9c121ecf779058fd348327b5e0c (diff) |
caddyfile: Support global config block; allow non-empty blocks w/ 0 keys
Diffstat (limited to 'caddyconfig/caddyfile')
-rw-r--r-- | caddyconfig/caddyfile/adapter.go | 8 | ||||
-rwxr-xr-x | caddyconfig/caddyfile/dispenser.go | 23 | ||||
-rwxr-xr-x | caddyconfig/caddyfile/parse.go | 2 |
3 files changed, 24 insertions, 9 deletions
diff --git a/caddyconfig/caddyfile/adapter.go b/caddyconfig/caddyfile/adapter.go index 377f77b..7a96e88 100644 --- a/caddyconfig/caddyfile/adapter.go +++ b/caddyconfig/caddyfile/adapter.go @@ -29,15 +29,15 @@ type Adapter struct { } // Adapt converts the Caddyfile config in body to Caddy JSON. -func (a Adapter) Adapt(body []byte, options map[string]string) ([]byte, []caddyconfig.Warning, error) { +func (a Adapter) Adapt(body []byte, options map[string]interface{}) ([]byte, []caddyconfig.Warning, error) { if a.ServerType == nil { return nil, nil, fmt.Errorf("no server type") } if options == nil { - options = make(map[string]string) + options = make(map[string]interface{}) } - filename := options["filename"] + filename, _ := options["filename"].(string) if filename == "" { filename = "Caddyfile" } @@ -80,7 +80,7 @@ type ServerType interface { // (e.g. CLI flags) and creates a Caddy // config, along with any warnings or // an error. - Setup([]ServerBlock, map[string]string) (*caddy.Config, []caddyconfig.Warning, error) + Setup([]ServerBlock, map[string]interface{}) (*caddy.Config, []caddyconfig.Warning, error) } // Interface guard diff --git a/caddyconfig/caddyfile/dispenser.go b/caddyconfig/caddyfile/dispenser.go index 66a3541..93f451e 100755 --- a/caddyconfig/caddyfile/dispenser.go +++ b/caddyconfig/caddyfile/dispenser.go @@ -186,10 +186,10 @@ func (d *Dispenser) File() string { // Args is a convenience function that loads the next arguments // (tokens on the same line) into an arbitrary number of strings -// pointed to in targets. If there are fewer tokens available -// than string pointers, the remaining strings will not be changed -// and false will be returned. If there were enough tokens available -// to fill the arguments, then true will be returned. +// pointed to in targets. If there are not enough argument tokens +// available to fill targets, false is returned and the remaining +// targets are left unchanged. If all the targets are filled, +// then true is returned. func (d *Dispenser) Args(targets ...*string) bool { for i := 0; i < len(targets); i++ { if !d.NextArg() { @@ -200,6 +200,21 @@ func (d *Dispenser) Args(targets ...*string) bool { return true } +// AllArgs is like Args, but if there are more argument tokens +// available than there are targets, false is returned. The +// number of available argument tokens must match the number of +// targets exactly to return true. +func (d *Dispenser) AllArgs(targets ...*string) bool { + if !d.Args(targets...) { + return false + } + if d.NextArg() { + d.Prev() + return false + } + return true +} + // RemainingArgs loads any more arguments (tokens on the same line) // into a slice and returns them. Open curly brace tokens also indicate // the end of arguments, and the curly brace is not included in diff --git a/caddyconfig/caddyfile/parse.go b/caddyconfig/caddyfile/parse.go index 3356f25..1862ad1 100755 --- a/caddyconfig/caddyfile/parse.go +++ b/caddyconfig/caddyfile/parse.go @@ -70,7 +70,7 @@ func (p *parser) parseAll() ([]ServerBlock, error) { if err != nil { return blocks, err } - if len(p.block.Keys) > 0 { + if len(p.block.Keys) > 0 || len(p.block.Segments) > 0 { blocks = append(blocks, p.block) } if p.nesting > 0 { |