| 208 | } |
| 209 | |
| 210 | func (p *parser) addresses() error { |
| 211 | var expectingAnother bool |
| 212 | |
| 213 | for { |
| 214 | value := p.Val() |
| 215 | token := p.Token() |
| 216 | |
| 217 | // Reject request matchers if trying to define them globally |
| 218 | if strings.HasPrefix(value, "@") { |
| 219 | return p.Errf("request matchers may not be defined globally, they must be in a site block; found %s", value) |
| 220 | } |
| 221 | |
| 222 | // Special case: import directive replaces tokens during parse-time |
| 223 | if value == "import" && p.isNewLine() { |
| 224 | err := p.doImport(0) |
| 225 | if err != nil { |
| 226 | return err |
| 227 | } |
| 228 | continue |
| 229 | } |
| 230 | |
| 231 | // Open brace definitely indicates end of addresses |
| 232 | if value == "{" { |
| 233 | if expectingAnother { |
| 234 | return p.Errf("Expected another address but had '%s' - check for extra comma", value) |
| 235 | } |
| 236 | // Mark this server block as being defined with braces. |
| 237 | // This is used to provide a better error message when |
| 238 | // the user may have tried to define two server blocks |
| 239 | // without having used braces, which are required in |
| 240 | // that case. |
| 241 | p.block.HasBraces = true |
| 242 | break |
| 243 | } |
| 244 | |
| 245 | // Users commonly forget to place a space between the address and the '{' |
| 246 | if strings.HasSuffix(value, "{") { |
| 247 | return p.Errf("Site addresses cannot end with a curly brace: '%s' - put a space between the token and the brace", value) |
| 248 | } |
| 249 | |
| 250 | if value != "" { // empty token possible if user typed "" |
| 251 | // Trailing comma indicates another address will follow, which |
| 252 | // may possibly be on the next line |
| 253 | if value[len(value)-1] == ',' { |
| 254 | value = value[:len(value)-1] |
| 255 | expectingAnother = true |
| 256 | } else { |
| 257 | expectingAnother = false // but we may still see another one on this line |
| 258 | } |
| 259 | |
| 260 | // If there's a comma here, it's probably because they didn't use a space |
| 261 | // between their two domains, e.g. "foo.com,bar.com", which would not be |
| 262 | // parsed as two separate site addresses. |
| 263 | if strings.Contains(value, ",") { |
| 264 | return p.Errf("Site addresses cannot contain a comma ',': '%s' - put a space after the comma to separate site addresses", value) |
| 265 | } |
| 266 | |
| 267 | // After the above, a comma surrounded by spaces would result |