| 1 | // Copyright 2015 Matthew Holt and The Caddy Authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package caddyfilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/ |
| 16 | |
| 17 | import ( |
| 18 | "errorsscip-go gomod github.com/golang/go/src go1.25.1 errors/" |
| 19 | "fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/" |
| 20 | "ioscip-go gomod github.com/golang/go/src go1.25.1 io/" |
| 21 | "logscip-go gomod github.com/golang/go/src go1.25.1 log/" |
| 22 | "strconvscip-go gomod github.com/golang/go/src go1.25.1 strconv/" |
| 23 | "stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/" |
| 24 | ) |
| 25 | |
| 26 | // Dispenser is a type that dispenses tokens, similarly to a lexer, |
| 27 | // except that it can do so with some notion of structure. An empty |
| 28 | // Dispenser is invalid; call NewDispenser to make a proper instance. |
| 29 | type Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser# struct { |
| 30 | tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens. []Tokenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token# |
| 31 | cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. int |
| 32 | nestingscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#nesting. int |
| 33 | |
| 34 | // A map of arbitrary context data that can be used |
| 35 | // to pass through some information to unmarshalers. |
| 36 | contextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#context. map[string]any |
| 37 | } |
| 38 | |
| 39 | // NewDispenser returns a Dispenser filled with the given tokens. |
| 40 | func NewDispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/NewDispenser().(tokens []Tokenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#) *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser# { |
| 41 | return &Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#{ |
| 42 | tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.: tokens, |
| 43 | cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.: -1, |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | // NewTestDispenser parses input into tokens and creates a new |
| 48 | // Dispenser for test purposes only; any errors are fatal. |
| 49 | func NewTestDispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/NewTestDispenser().(input string) *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser# { |
| 50 | tokens, err := allTokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/allTokens().("Testfile", []byte(input)) |
| 51 | if err != nil && err != ioscip-go gomod github.com/golang/go/src go1.25.1 io/.EOFscip-go gomod github.com/golang/go/src go1.25.1 io/EOF. { |
| 52 | logscip-go gomod github.com/golang/go/src go1.25.1 log/.Fatalfscip-go gomod github.com/golang/go/src go1.25.1 log/Fatalf().("getting all tokens from input: %v", err) |
| 53 | } |
| 54 | return NewDispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/NewDispenser().(tokens) |
| 55 | } |
| 56 | |
| 57 | // Next loads the next token. Returns true if a token |
| 58 | // was loaded; false otherwise. If false, all tokens |
| 59 | // have been consumed. |
| 60 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) Nextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Next().() bool { |
| 61 | if d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. < len(d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.)-1 { |
| 62 | d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.++ |
| 63 | return true |
| 64 | } |
| 65 | return false |
| 66 | } |
| 67 | |
| 68 | // Prev moves to the previous token. It does the inverse |
| 69 | // of Next(), except this function may decrement the cursor |
| 70 | // to -1 so that the next call to Next() points to the |
| 71 | // first token; this allows dispensing to "start over". This |
| 72 | // method returns true if the cursor ends up pointing to a |
| 73 | // valid token. |
| 74 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) Prevscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Prev().() bool { |
| 75 | if d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. > -1 { |
| 76 | d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.-- |
| 77 | return d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. > -1 |
| 78 | } |
| 79 | return false |
| 80 | } |
| 81 | |
| 82 | // NextArg loads the next token if it is on the same |
| 83 | // line and if it is not a block opening (open curly |
| 84 | // brace). Returns true if an argument token was |
| 85 | // loaded; false otherwise. If false, all tokens on |
| 86 | // the line have been consumed except for potentially |
| 87 | // a block opening. It handles imported tokens |
| 88 | // correctly. |
| 89 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) NextArgscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#NextArg().() bool { |
| 90 | if !d.nextOnSameLinescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#nextOnSameLine().() { |
| 91 | return false |
| 92 | } |
| 93 | if d.Valscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Val().() == "{" { |
| 94 | // roll back; a block opening is not an argument |
| 95 | d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.-- |
| 96 | return false |
| 97 | } |
| 98 | return true |
| 99 | } |
| 100 | |
| 101 | // nextOnSameLine advances the cursor if the next |
| 102 | // token is on the same line of the same file. |
| 103 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) nextOnSameLinescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#nextOnSameLine().() bool { |
| 104 | if d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. < 0 { |
| 105 | d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.++ |
| 106 | return true |
| 107 | } |
| 108 | if d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. >= len(d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.)-1 { |
| 109 | return false |
| 110 | } |
| 111 | curr := d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.[d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.] |
| 112 | next := d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.[d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.+1] |
| 113 | if !isNextOnNewLinescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/isNextOnNewLine().(curr, next) { |
| 114 | d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.++ |
| 115 | return true |
| 116 | } |
| 117 | return false |
| 118 | } |
| 119 | |
| 120 | // NextLine loads the next token only if it is not on the same |
| 121 | // line as the current token, and returns true if a token was |
| 122 | // loaded; false otherwise. If false, there is not another token |
| 123 | // or it is on the same line. It handles imported tokens correctly. |
| 124 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) NextLinescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#NextLine().() bool { |
| 125 | if d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. < 0 { |
| 126 | d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.++ |
| 127 | return true |
| 128 | } |
| 129 | if d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. >= len(d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.)-1 { |
| 130 | return false |
| 131 | } |
| 132 | curr := d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.[d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.] |
| 133 | next := d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.[d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.+1] |
| 134 | if isNextOnNewLinescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/isNextOnNewLine().(curr, next) { |
| 135 | d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.++ |
| 136 | return true |
| 137 | } |
| 138 | return false |
| 139 | } |
| 140 | |
| 141 | // NextBlock can be used as the condition of a for loop |
| 142 | // to load the next token as long as it opens a block or |
| 143 | // is already in a block nested more than initialNestingLevel. |
| 144 | // In other words, a loop over NextBlock() will iterate |
| 145 | // all tokens in the block assuming the next token is an |
| 146 | // open curly brace, until the matching closing brace. |
| 147 | // The open and closing brace tokens for the outer-most |
| 148 | // block will be consumed internally and omitted from |
| 149 | // the iteration. |
| 150 | // |
| 151 | // Proper use of this method looks like this: |
| 152 | // |
| 153 | // for nesting := d.Nesting(); d.NextBlock(nesting); { |
| 154 | // } |
| 155 | // |
| 156 | // However, in simple cases where it is known that the |
| 157 | // Dispenser is new and has not already traversed state |
| 158 | // by a loop over NextBlock(), this will do: |
| 159 | // |
| 160 | // for d.NextBlock(0) { |
| 161 | // } |
| 162 | // |
| 163 | // As with other token parsing logic, a loop over |
| 164 | // NextBlock() should be contained within a loop over |
| 165 | // Next(), as it is usually prudent to skip the initial |
| 166 | // token. |
| 167 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) NextBlockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#NextBlock().(initialNestingLevel int) bool { |
| 168 | if d.nestingscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#nesting. > initialNestingLevel { |
| 169 | if !d.Nextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Next().() { |
| 170 | return false // should be EOF error |
| 171 | } |
| 172 | if d.Valscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Val().() == "}" && !d.nextOnSameLinescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#nextOnSameLine().() { |
| 173 | d.nestingscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#nesting.-- |
| 174 | } else if d.Valscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Val().() == "{" && !d.nextOnSameLinescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#nextOnSameLine().() { |
| 175 | d.nestingscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#nesting.++ |
| 176 | } |
| 177 | return d.nestingscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#nesting. > initialNestingLevel |
| 178 | } |
| 179 | if !d.nextOnSameLinescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#nextOnSameLine().() { // block must open on same line |
| 180 | return false |
| 181 | } |
| 182 | if d.Valscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Val().() != "{" { |
| 183 | d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.-- // roll back if not opening brace |
| 184 | return false |
| 185 | } |
| 186 | d.Nextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Next().() // consume open curly brace |
| 187 | if d.Valscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Val().() == "}" { |
| 188 | return false // open and then closed right away |
| 189 | } |
| 190 | d.nestingscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#nesting.++ |
| 191 | return true |
| 192 | } |
| 193 | |
| 194 | // Nesting returns the current nesting level. Necessary |
| 195 | // if using NextBlock() |
| 196 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) Nestingscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Nesting().() int { |
| 197 | return d.nestingscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#nesting. |
| 198 | } |
| 199 | |
| 200 | // Val gets the text of the current token. If there is no token |
| 201 | // loaded, it returns empty string. |
| 202 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) Valscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Val().() string { |
| 203 | if d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. < 0 || d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. >= len(d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.) { |
| 204 | return "" |
| 205 | } |
| 206 | return d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.[d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.].Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#Text. |
| 207 | } |
| 208 | |
| 209 | // ValRaw gets the raw text of the current token (including quotes). |
| 210 | // If the token was a heredoc, then the delimiter is not included, |
| 211 | // because that is not relevant to any unmarshaling logic at this time. |
| 212 | // If there is no token loaded, it returns empty string. |
| 213 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) ValRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#ValRaw().() string { |
| 214 | if d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. < 0 || d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. >= len(d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.) { |
| 215 | return "" |
| 216 | } |
| 217 | quote := d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.[d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.].wasQuotedscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#wasQuoted. |
| 218 | if quote > 0 && quote != '<' { |
| 219 | // string literal |
| 220 | return string(quote) + d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.[d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.].Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#Text. + string(quote) |
| 221 | } |
| 222 | return d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.[d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.].Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#Text. |
| 223 | } |
| 224 | |
| 225 | // ScalarVal gets value of the current token, converted to the closest |
| 226 | // scalar type. If there is no token loaded, it returns nil. |
| 227 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) ScalarValscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#ScalarVal().() any { |
| 228 | if d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. < 0 || d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. >= len(d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.) { |
| 229 | return nil |
| 230 | } |
| 231 | quote := d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.[d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.].wasQuotedscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#wasQuoted. |
| 232 | text := d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.[d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.].Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#Text. |
| 233 | |
| 234 | if quote > 0 { |
| 235 | return text // string literal |
| 236 | } |
| 237 | if num, err := strconvscip-go gomod github.com/golang/go/src go1.25.1 strconv/.Atoiscip-go gomod github.com/golang/go/src go1.25.1 strconv/Atoi().(text); err == nil { |
| 238 | return num |
| 239 | } |
| 240 | if num, err := strconvscip-go gomod github.com/golang/go/src go1.25.1 strconv/.ParseFloatscip-go gomod github.com/golang/go/src go1.25.1 strconv/ParseFloat().(text, 64); err == nil { |
| 241 | return num |
| 242 | } |
| 243 | if bool, err := strconvscip-go gomod github.com/golang/go/src go1.25.1 strconv/.ParseBoolscip-go gomod github.com/golang/go/src go1.25.1 strconv/ParseBool().(text); err == nil { |
| 244 | return bool |
| 245 | } |
| 246 | return text |
| 247 | } |
| 248 | |
| 249 | // Line gets the line number of the current token. |
| 250 | // If there is no token loaded, it returns 0. |
| 251 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) Linescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Line().() int { |
| 252 | if d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. < 0 || d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. >= len(d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.) { |
| 253 | return 0 |
| 254 | } |
| 255 | return d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.[d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.].Linescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#Line. |
| 256 | } |
| 257 | |
| 258 | // File gets the filename where the current token originated. |
| 259 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) Filescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#File().() string { |
| 260 | if d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. < 0 || d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. >= len(d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.) { |
| 261 | return "" |
| 262 | } |
| 263 | return d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.[d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.].Filescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#File. |
| 264 | } |
| 265 | |
| 266 | // Args is a convenience function that loads the next arguments |
| 267 | // (tokens on the same line) into an arbitrary number of strings |
| 268 | // pointed to in targets. If there are not enough argument tokens |
| 269 | // available to fill targets, false is returned and the remaining |
| 270 | // targets are left unchanged. If all the targets are filled, |
| 271 | // then true is returned. |
| 272 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) Argsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Args().(targets ...*string) bool { |
| 273 | for i := range targets { |
| 274 | if !d.NextArgscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#NextArg().() { |
| 275 | return false |
| 276 | } |
| 277 | *targets[i] = d.Valscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Val().() |
| 278 | } |
| 279 | return true |
| 280 | } |
| 281 | |
| 282 | // AllArgs is like Args, but if there are more argument tokens |
| 283 | // available than there are targets, false is returned. The |
| 284 | // number of available argument tokens must match the number of |
| 285 | // targets exactly to return true. |
| 286 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) AllArgsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#AllArgs().(targets ...*string) bool { |
| 287 | if !d.Argsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Args().(targets...) { |
| 288 | return false |
| 289 | } |
| 290 | if d.NextArgscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#NextArg().() { |
| 291 | d.Prevscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Prev().() |
| 292 | return false |
| 293 | } |
| 294 | return true |
| 295 | } |
| 296 | |
| 297 | // CountRemainingArgs counts the amount of remaining arguments |
| 298 | // (tokens on the same line) without consuming the tokens. |
| 299 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) CountRemainingArgsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#CountRemainingArgs().() int { |
| 300 | count := 0 |
| 301 | for d.NextArgscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#NextArg().() { |
| 302 | count++ |
| 303 | } |
| 304 | for i := 0; i < count; i++ { |
| 305 | d.Prevscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Prev().() |
| 306 | } |
| 307 | return count |
| 308 | } |
| 309 | |
| 310 | // RemainingArgs loads any more arguments (tokens on the same line) |
| 311 | // into a slice of strings and returns them. Open curly brace tokens |
| 312 | // also indicate the end of arguments, and the curly brace is not |
| 313 | // included in the return value nor is it loaded. |
| 314 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) RemainingArgsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#RemainingArgs().() []string { |
| 315 | var args []string |
| 316 | for d.NextArgscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#NextArg().() { |
| 317 | args = append(args, d.Valscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Val().()) |
| 318 | } |
| 319 | return args |
| 320 | } |
| 321 | |
| 322 | // RemainingArgsRaw loads any more arguments (tokens on the same line, |
| 323 | // retaining quotes) into a slice of strings and returns them. |
| 324 | // Open curly brace tokens also indicate the end of arguments, |
| 325 | // and the curly brace is not included in the return value nor is it loaded. |
| 326 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) RemainingArgsRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#RemainingArgsRaw().() []string { |
| 327 | var args []string |
| 328 | for d.NextArgscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#NextArg().() { |
| 329 | args = append(args, d.ValRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#ValRaw().()) |
| 330 | } |
| 331 | return args |
| 332 | } |
| 333 | |
| 334 | // RemainingArgsAsTokens loads any more arguments (tokens on the same line) |
| 335 | // into a slice of Token-structs and returns them. Open curly brace tokens |
| 336 | // also indicate the end of arguments, and the curly brace is not included |
| 337 | // in the return value nor is it loaded. |
| 338 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) RemainingArgsAsTokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#RemainingArgsAsTokens().() []Tokenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token# { |
| 339 | var args []Tokenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token# |
| 340 | for d.NextArgscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#NextArg().() { |
| 341 | args = append(args, d.Tokenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Token().()) |
| 342 | } |
| 343 | return args |
| 344 | } |
| 345 | |
| 346 | // NewFromNextSegment returns a new dispenser with a copy of |
| 347 | // the tokens from the current token until the end of the |
| 348 | // "directive" whether that be to the end of the line or |
| 349 | // the end of a block that starts at the end of the line; |
| 350 | // in other words, until the end of the segment. |
| 351 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) NewFromNextSegmentscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#NewFromNextSegment().() *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser# { |
| 352 | return NewDispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/NewDispenser().(d.NextSegmentscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#NextSegment().()) |
| 353 | } |
| 354 | |
| 355 | // NextSegment returns a copy of the tokens from the current |
| 356 | // token until the end of the line or block that starts at |
| 357 | // the end of the line. |
| 358 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) NextSegmentscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#NextSegment().() Segmentscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Segment# { |
| 359 | tkns := Segmentscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Segment#{d.Tokenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Token().()} |
| 360 | for d.NextArgscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#NextArg().() { |
| 361 | tkns = append(tkns, d.Tokenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Token().()) |
| 362 | } |
| 363 | var openedBlock bool |
| 364 | for nesting := d.Nestingscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Nesting().(); d.NextBlockscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#NextBlock().(nesting); { |
| 365 | if !openedBlock { |
| 366 | // because NextBlock() consumes the initial open |
| 367 | // curly brace, we rewind here to append it, since |
| 368 | // our case is special in that we want the new |
| 369 | // dispenser to have all the tokens including |
| 370 | // surrounding curly braces |
| 371 | d.Prevscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Prev().() |
| 372 | tkns = append(tkns, d.Tokenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Token().()) |
| 373 | d.Nextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Next().() |
| 374 | openedBlock = true |
| 375 | } |
| 376 | tkns = append(tkns, d.Tokenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Token().()) |
| 377 | } |
| 378 | if openedBlock { |
| 379 | // include closing brace |
| 380 | tkns = append(tkns, d.Tokenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Token().()) |
| 381 | |
| 382 | // do not consume the closing curly brace; the |
| 383 | // next iteration of the enclosing loop will |
| 384 | // call Next() and consume it |
| 385 | } |
| 386 | return tkns |
| 387 | } |
| 388 | |
| 389 | // Token returns the current token. |
| 390 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) Tokenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Token().() Tokenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token# { |
| 391 | if d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. < 0 || d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. >= len(d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.) { |
| 392 | return Tokenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#{} |
| 393 | } |
| 394 | return d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.[d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.] |
| 395 | } |
| 396 | |
| 397 | // Reset sets d's cursor to the beginning, as |
| 398 | // if this was a new and unused dispenser. |
| 399 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) Resetscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Reset().() { |
| 400 | d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. = -1 |
| 401 | d.nestingscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#nesting. = 0 |
| 402 | } |
| 403 | |
| 404 | // ArgErr returns an argument error, meaning that another |
| 405 | // argument was expected but not found. In other words, |
| 406 | // a line break or open curly brace was encountered instead of |
| 407 | // an argument. |
| 408 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) ArgErrscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#ArgErr().() error { |
| 409 | if d.Valscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Val().() == "{" { |
| 410 | return d.Errscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Err().("unexpected token '{', expecting argument") |
| 411 | } |
| 412 | return d.Errfscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Errf().("wrong argument count or unexpected line ending after '%s'", d.Valscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Val().()) |
| 413 | } |
| 414 | |
| 415 | // SyntaxErr creates a generic syntax error which explains what was |
| 416 | // found and what was expected. |
| 417 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) SyntaxErrscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#SyntaxErr().(expected string) error { |
| 418 | msg := fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Sprintf().("syntax error: unexpected token '%s', expecting '%s', at %s:%d import chain: ['%s']", d.Valscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Val().(), expected, d.Filescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#File().(), d.Linescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Line().(), stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.Joinscip-go gomod github.com/golang/go/src go1.25.1 strings/Join().(d.Tokenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Token().().importsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#imports., "','")) |
| 419 | return errorsscip-go gomod github.com/golang/go/src go1.25.1 errors/.Newscip-go gomod github.com/golang/go/src go1.25.1 errors/New().(msg) |
| 420 | } |
| 421 | |
| 422 | // EOFErr returns an error indicating that the dispenser reached |
| 423 | // the end of the input when searching for the next token. |
| 424 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) EOFErrscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#EOFErr().() error { |
| 425 | return d.Errfscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Errf().("unexpected EOF") |
| 426 | } |
| 427 | |
| 428 | // Err generates a custom parse-time error with a message of msg. |
| 429 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) Errscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Err().(msg string) error { |
| 430 | return d.WrapErrscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#WrapErr().(errorsscip-go gomod github.com/golang/go/src go1.25.1 errors/.Newscip-go gomod github.com/golang/go/src go1.25.1 errors/New().(msg)) |
| 431 | } |
| 432 | |
| 433 | // Errf is like Err, but for formatted error messages |
| 434 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) Errfscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Errf().(format string, args ...any) error { |
| 435 | return d.WrapErrscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#WrapErr().(fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().(format, args...)) |
| 436 | } |
| 437 | |
| 438 | // WrapErr takes an existing error and adds the Caddyfile file and line number. |
| 439 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) WrapErrscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#WrapErr().(err error) error { |
| 440 | if len(d.Tokenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Token().().importsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#imports.) > 0 { |
| 441 | return fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("%w, at %s:%d import chain ['%s']", err, d.Filescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#File().(), d.Linescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Line().(), stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.Joinscip-go gomod github.com/golang/go/src go1.25.1 strings/Join().(d.Tokenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Token().().importsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token#imports., "','")) |
| 442 | } |
| 443 | return fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("%w, at %s:%d", err, d.Filescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#File().(), d.Linescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Line().()) |
| 444 | } |
| 445 | |
| 446 | // Delete deletes the current token and returns the updated slice |
| 447 | // of tokens. The cursor is not advanced to the next token. |
| 448 | // Because deletion modifies the underlying slice, this method |
| 449 | // should only be called if you have access to the original slice |
| 450 | // of tokens and/or are using the slice of tokens outside this |
| 451 | // Dispenser instance. If you do not re-assign the slice with the |
| 452 | // return value of this method, inconsistencies in the token |
| 453 | // array will become apparent (or worse, hide from you like they |
| 454 | // did me for 3 and a half freaking hours late one night). |
| 455 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) Deletescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#Delete().() []Tokenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token# { |
| 456 | if d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. >= 0 && d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. <= len(d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.)-1 { |
| 457 | d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens. = append(d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.[:d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.], d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.[d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.+1:]...) |
| 458 | d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.-- |
| 459 | } |
| 460 | return d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens. |
| 461 | } |
| 462 | |
| 463 | // DeleteN is the same as Delete, but can delete many tokens at once. |
| 464 | // If there aren't N tokens available to delete, none are deleted. |
| 465 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) DeleteNscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#DeleteN().(amount int) []Tokenscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Token# { |
| 466 | if amount > 0 && d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. >= (amount-1) && d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. <= len(d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.)-1 { |
| 467 | d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens. = append(d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.[:d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.-(amount-1)], d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.[d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.+1:]...) |
| 468 | d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. -= amount |
| 469 | } |
| 470 | return d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens. |
| 471 | } |
| 472 | |
| 473 | // SetContext sets a key-value pair in the context map. |
| 474 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) SetContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#SetContext().(key string, value any) { |
| 475 | if d.contextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#context. == nil { |
| 476 | d.contextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#context. = make(map[string]any) |
| 477 | } |
| 478 | d.contextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#context.[key] = value |
| 479 | } |
| 480 | |
| 481 | // GetContext gets the value of a key in the context map. |
| 482 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) GetContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#GetContext().(key string) any { |
| 483 | if d.contextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#context. == nil { |
| 484 | return nil |
| 485 | } |
| 486 | return d.contextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#context.[key] |
| 487 | } |
| 488 | |
| 489 | // GetContextString gets the value of a key in the context map |
| 490 | // as a string, or an empty string if the key does not exist. |
| 491 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) GetContextStringscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#GetContextString().(key string) string { |
| 492 | if d.contextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#context. == nil { |
| 493 | return "" |
| 494 | } |
| 495 | if val, ok := d.contextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#context.[key].(string); ok { |
| 496 | return val |
| 497 | } |
| 498 | return "" |
| 499 | } |
| 500 | |
| 501 | // isNewLine determines whether the current token is on a different |
| 502 | // line (higher line number) than the previous token. It handles imported |
| 503 | // tokens correctly. If there isn't a previous token, it returns true. |
| 504 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) isNewLinescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#isNewLine().() bool { |
| 505 | if d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. < 1 { |
| 506 | return true |
| 507 | } |
| 508 | if d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. > len(d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.)-1 { |
| 509 | return false |
| 510 | } |
| 511 | |
| 512 | prev := d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.[d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.-1] |
| 513 | curr := d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.[d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.] |
| 514 | return isNextOnNewLinescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/isNextOnNewLine().(prev, curr) |
| 515 | } |
| 516 | |
| 517 | // isNextOnNewLine determines whether the current token is on a different |
| 518 | // line (higher line number) than the next token. It handles imported |
| 519 | // tokens correctly. If there isn't a next token, it returns true. |
| 520 | func (d *Dispenserscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#) isNextOnNewLinescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#isNextOnNewLine().() bool { |
| 521 | if d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. < 0 { |
| 522 | return false |
| 523 | } |
| 524 | if d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor. >= len(d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.)-1 { |
| 525 | return true |
| 526 | } |
| 527 | |
| 528 | curr := d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.[d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.] |
| 529 | next := d.tokensscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#tokens.[d.cursorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/Dispenser#cursor.+1] |
| 530 | return isNextOnNewLinescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/isNextOnNewLine().(curr, next) |
| 531 | } |
| 532 | |
| 533 | const MatcherNameCtxKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig/caddyfile`/MatcherNameCtxKey. = "matcher_name" |