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

Function NewShorthandReplacer

caddyconfig/httpcaddyfile/shorthands.go:20–48  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18}
19
20func NewShorthandReplacer() ShorthandReplacer {
21 // replace shorthand placeholders (which are convenient
22 // when writing a Caddyfile) with their actual placeholder
23 // identifiers or variable names
24 replacer := strings.NewReplacer(placeholderShorthands()...)
25
26 // these are placeholders that allow a user-defined final
27 // parameters, but we still want to provide a shorthand
28 // for those, so we use a regexp to replace
29 regexpReplacements := []ComplexShorthandReplacer{
30 {regexp.MustCompile(`{header\.([\w-]*)}`), "{http.request.header.$1}"},
31 {regexp.MustCompile(`{cookie\.([\w-]*)}`), "{http.request.cookie.$1}"},
32 {regexp.MustCompile(`{labels\.([\w-]*)}`), "{http.request.host.labels.$1}"},
33 {regexp.MustCompile(`{path\.([\w-]*)}`), "{http.request.uri.path.$1}"},
34 {regexp.MustCompile(`{file\.([\w-]*)}`), "{http.request.uri.path.file.$1}"},
35 {regexp.MustCompile(`{query\.([\w-]*)}`), "{http.request.uri.query.$1}"},
36 {regexp.MustCompile(`{re\.([\w-\.]*)}`), "{http.regexp.$1}"},
37 {regexp.MustCompile(`{vars\.([\w-]*)}`), "{http.vars.$1}"},
38 {regexp.MustCompile(`{rp\.([\w-\.]*)}`), "{http.reverse_proxy.$1}"},
39 {regexp.MustCompile(`{resp\.([\w-\.]*)}`), "{http.intercept.$1}"},
40 {regexp.MustCompile(`{err\.([\w-\.]*)}`), "{http.error.$1}"},
41 {regexp.MustCompile(`{file_match\.([\w-]*)}`), "{http.matchers.file.$1}"},
42 }
43
44 return ShorthandReplacer{
45 complex: regexpReplacements,
46 simple: replacer,
47 }
48}
49
50// placeholderShorthands returns a slice of old-new string pairs,
51// where the left of the pair is a placeholder shorthand that may

Callers 1

SetupMethod · 0.85

Calls 1

placeholderShorthandsFunction · 0.85

Tested by

no test coverage detected