-
Notifications
You must be signed in to change notification settings - Fork 0
/
url.go
41 lines (32 loc) · 905 Bytes
/
url.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package caddylura
import (
"regexp"
"strings"
)
var (
simpleURLKeysPattern = regexp.MustCompile(`\{([\w\-.:/]+)}`)
caddyPlaceholdersPattern = regexp.MustCompile(`({{\.Resp042_\.(.+?)}})`)
)
type paramsSet map[string]interface{}
func newParamsSetFromPattern(subject string) paramsSet {
matches := simpleURLKeysPattern.FindAllStringSubmatch(subject, -1)
kset := make(map[string]interface{}, len(matches))
for _, v := range matches {
kset[v[1]] = nil
}
return kset
}
func (s paramsSet) contains(v string) bool {
_, ok := s[v]
return ok
}
func processBackendUrlPattern(subject string, backendParams paramsSet) string {
output := subject
for p := range backendParams {
output = strings.ReplaceAll(output, "{"+p+"}", "{resp042_."+p+"}")
}
return output
}
func applyCaddyPlaceholders(subject string) string {
return caddyPlaceholdersPattern.ReplaceAllString(subject, "{${2}}")
}