parseRoot parses the root directive. Syntax: root [<matcher>] <path>
(h Helper)
| 637 | // |
| 638 | // root [<matcher>] <path> |
| 639 | func parseRoot(h Helper) ([]ConfigValue, error) { |
| 640 | h.Next() // consume directive name |
| 641 | |
| 642 | // count the tokens to determine what to do |
| 643 | argsCount := h.CountRemainingArgs() |
| 644 | if argsCount == 0 { |
| 645 | return nil, h.Errf("too few arguments; must have at least a root path") |
| 646 | } |
| 647 | if argsCount > 2 { |
| 648 | return nil, h.Errf("too many arguments; should only be a matcher and a path") |
| 649 | } |
| 650 | |
| 651 | // with only one arg, assume it's a root path with no matcher token |
| 652 | if argsCount == 1 { |
| 653 | if !h.NextArg() { |
| 654 | return nil, h.ArgErr() |
| 655 | } |
| 656 | // store the unmatched root in block state so sibling directives can access it |
| 657 | h.BlockState["root"] = h.Val() |
| 658 | return h.NewRoute(nil, caddyhttp.VarsMiddleware{"root": h.Val()}), nil |
| 659 | } |
| 660 | |
| 661 | // parse the matcher token into a matcher set |
| 662 | userMatcherSet, err := h.ExtractMatcherSet() |
| 663 | if err != nil { |
| 664 | return nil, err |
| 665 | } |
| 666 | h.Next() // consume directive name again, matcher parsing does a reset |
| 667 | |
| 668 | // advance to the root path |
| 669 | if !h.NextArg() { |
| 670 | return nil, h.ArgErr() |
| 671 | } |
| 672 | // store the unmatched root in state so sibling/child directives can access it |
| 673 | if userMatcherSet == nil { |
| 674 | h.BlockState["root"] = h.Val() |
| 675 | } |
| 676 | // make the route with the matcher |
| 677 | return h.NewRoute(userMatcherSet, caddyhttp.VarsMiddleware{"root": h.Val()}), nil |
| 678 | } |
| 679 | |
| 680 | // parseFilesystem parses the fs directive. Syntax: |
| 681 | // |
nothing calls this directly
no test coverage detected