1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-20 03:17:04 +00:00

new apps/switch (beta)

This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-08-17 21:53:17 +03:00
parent a61f743fa8
commit 589c8c6242
14 changed files with 678 additions and 48 deletions

View File

@@ -19,7 +19,7 @@ var (
)
var (
handlerNames = make(map[*nameExpr]string)
handlerNames = make(map[*NameExpr]string)
handlerNamesMu sync.RWMutex
)
@@ -44,19 +44,22 @@ func SetHandlerName(original string, replacement string) {
// when a handler name is declared as it's and cause regex parsing expression error,
// e.g. `iris/cache/client.(*Handler).ServeHTTP-fm`
regex, _ := regexp.Compile(original)
handlerNames[&nameExpr{
handlerNames[&NameExpr{
literal: original,
regex: regex,
}] = replacement
handlerNamesMu.Unlock()
}
type nameExpr struct {
// NameExpr regex or literal comparison through `MatchString`.
type NameExpr struct {
regex *regexp.Regexp
literal string
}
func (expr *nameExpr) MatchString(s string) bool {
// MatchString reports whether "s" is literal of "literal"
// or it matches the regex expression at "regex".
func (expr *NameExpr) MatchString(s string) bool {
if expr.literal == s { // if matches as string, as it's.
return true
}