MCPcopy
hub / github.com/caddyserver/caddy / parseRoot

Function parseRoot

caddyconfig/httpcaddyfile/builtins.go:639–678  ·  view source on GitHub ↗

parseRoot parses the root directive. Syntax: root [<matcher>] <path>

(h Helper)

Source from the content-addressed store, hash-verified

637//
638// root [<matcher>] <path>
639func 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//

Callers

nothing calls this directly

Calls 8

CountRemainingArgsMethod · 0.80
ErrfMethod · 0.80
NextArgMethod · 0.80
ArgErrMethod · 0.80
ValMethod · 0.80
NewRouteMethod · 0.80
ExtractMatcherSetMethod · 0.80
NextMethod · 0.65

Tested by

no test coverage detected