1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-23 20:05:59 +00:00
Former-commit-id: fe6305deed00e170bf4d39a12c0644fe686e0a24
This commit is contained in:
Gerasimos (Makis) Maropoulos
2018-10-21 19:20:05 +03:00
parent dbba631df4
commit 3962710d3d
109 changed files with 4383 additions and 2658 deletions

View File

@@ -7,15 +7,9 @@ import (
"strings"
"github.com/kataras/iris/core/netutil"
"github.com/kataras/iris/core/router/macro/interpreter/lexer"
)
const (
// ParamStart the character in string representation where the underline router starts its dynamic named parameter.
ParamStart = ":"
// WildcardParamStart the character in string representation where the underline router starts its dynamic wildcard
// path parameter.
WildcardParamStart = "*"
"github.com/kataras/iris/macro"
"github.com/kataras/iris/macro/interpreter/ast"
"github.com/kataras/iris/macro/interpreter/lexer"
)
// Param receives a parameter name prefixed with the ParamStart symbol.
@@ -31,6 +25,26 @@ func WildcardParam(name string) string {
return prefix(name, WildcardParamStart)
}
func convertMacroTmplToNodePath(tmpl macro.Template) string {
routePath := tmpl.Src
if len(routePath) > 1 && routePath[len(routePath)-1] == '/' {
routePath = routePath[0 : len(routePath)-1] // remove any last "/"
}
// if it has started with {} and it's valid
// then the tmpl.Params will be filled,
// so no any further check needed.
for _, p := range tmpl.Params {
if ast.IsTrailing(p.Type) {
routePath = strings.Replace(routePath, p.Src, WildcardParam(p.Name), 1)
} else {
routePath = strings.Replace(routePath, p.Src, Param(p.Name), 1)
}
}
return routePath
}
func prefix(s string, prefix string) string {
if !strings.HasPrefix(s, prefix) {
return prefix + s