MCPcopy Index your code
hub / github.com/coder/coder / Compile

Method Compile

coderd/httpmw/patternmatcher/routepatterns.go:32–50  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

30}
31
32func (rp RoutePatterns) Compile() (*regexp.Regexp, error) {
33 patterns := make([]string, len(rp))
34 for i, p := range rp {
35 p = strings.ReplaceAll(p, "**", ".+")
36 p = strings.ReplaceAll(p, "*", "[^/]+")
37 if !strings.HasSuffix(p, "/") {
38 p += "/?"
39 }
40 patterns[i] = p
41 }
42
43 pattern := fmt.Sprintf("^(%s)$", strings.Join(patterns, "|"))
44 re, err := regexp.Compile(pattern)
45 if err != nil {
46 return nil, xerrors.Errorf("compile regex %q: %w", pattern, err)
47 }
48
49 return re, nil
50}

Callers 8

MustCompileMethod · 0.95
Test_RoutePatternsFunction · 0.80
CompileHostnamePatternFunction · 0.80
ConvertConfigFunction · 0.80
compileMethod · 0.80
updateAutoversionFileFunction · 0.80
autoversionFileMethod · 0.80

Calls 1

ErrorfMethod · 0.45

Tested by 1

Test_RoutePatternsFunction · 0.64