diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2020-02-14 11:00:16 -0700 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2020-02-14 11:01:09 -0700 |
commit | 15bf9c196c5972051f40ebadf50811bd06e328dd (patch) | |
tree | 03362b73a9bdd923bf4f252e346a8441f5de04b0 /caddyconfig/caddyfile | |
parent | eb80165583776d878256359f1635ffa9a17f0171 (diff) |
caddyfile: Refactor; NewFromNextSegment(); fix repeated matchers
Now multiple instances of the same matcher can be used within a named
matcher without overwriting previous ones.
Diffstat (limited to 'caddyconfig/caddyfile')
-rwxr-xr-x | caddyconfig/caddyfile/dispenser.go | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/caddyconfig/caddyfile/dispenser.go b/caddyconfig/caddyfile/dispenser.go index 4ed9325..932ab61 100755 --- a/caddyconfig/caddyfile/dispenser.go +++ b/caddyconfig/caddyfile/dispenser.go @@ -249,13 +249,20 @@ func (d *Dispenser) RemainingArgs() []string { return args } -// NewFromNextTokens returns a new dispenser with a copy of +// NewFromNextSegment returns a new dispenser with a copy of // the tokens from the current token until the end of the // "directive" whether that be to the end of the line or // the end of a block that starts at the end of the line; // in other words, until the end of the segment. -func (d *Dispenser) NewFromNextTokens() *Dispenser { - tkns := []Token{d.Token()} +func (d *Dispenser) NewFromNextSegment() *Dispenser { + return NewDispenser(d.NextSegment()) +} + +// NextSegment returns a copy of the tokens from the current +// token until the end of the line or block that starts at +// the end of the line. +func (d *Dispenser) NextSegment() Segment { + tkns := Segment{d.Token()} for d.NextArg() { tkns = append(tkns, d.Token()) } @@ -282,7 +289,7 @@ func (d *Dispenser) NewFromNextTokens() *Dispenser { // next iteration of the enclosing loop will // call Next() and consume it } - return NewDispenser(tkns) + return tkns } // Token returns the current token. |