UnmarshalCaddyfile implements caddyfile.Unmarshaler.
(d *caddyfile.Dispenser)
| 262 | |
| 263 | // UnmarshalCaddyfile implements caddyfile.Unmarshaler. |
| 264 | func (m *MatchVarsRE) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { |
| 265 | if *m == nil { |
| 266 | *m = make(map[string]*MatchRegexp) |
| 267 | } |
| 268 | // iterate to merge multiple matchers into one |
| 269 | for d.Next() { |
| 270 | var first, second, third string |
| 271 | if !d.Args(&first, &second) { |
| 272 | return d.ArgErr() |
| 273 | } |
| 274 | |
| 275 | var name, field, val string |
| 276 | if d.Args(&third) { |
| 277 | name = first |
| 278 | field = second |
| 279 | val = third |
| 280 | } else { |
| 281 | field = first |
| 282 | val = second |
| 283 | } |
| 284 | |
| 285 | // Default to the named matcher's name, if no regexp name is provided |
| 286 | if name == "" { |
| 287 | name = d.GetContextString(caddyfile.MatcherNameCtxKey) |
| 288 | } |
| 289 | |
| 290 | (*m)[field] = &MatchRegexp{Pattern: val, Name: name} |
| 291 | if d.NextBlock(0) { |
| 292 | return d.Err("malformed vars_regexp matcher: blocks are not supported") |
| 293 | } |
| 294 | } |
| 295 | return nil |
| 296 | } |
| 297 | |
| 298 | // Provision compiles m's regular expressions. |
| 299 | func (m MatchVarsRE) Provision(ctx caddy.Context) error { |