mirror of
https://github.com/kataras/iris.git
synced 2025-12-21 03:47:04 +00:00
partial cleanup of the macro pkg and move it from /core/router to the root because it may be used by the end-developers now to ammend the available macros per application
Former-commit-id: 951a5e7a401af25ecaa904ff6463b0def2c87afb
This commit is contained in:
@@ -7,7 +7,9 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/kataras/iris/core/netutil"
|
||||
"github.com/kataras/iris/core/router/macro/interpreter/lexer"
|
||||
"github.com/kataras/iris/macro"
|
||||
"github.com/kataras/iris/macro/interpreter/ast"
|
||||
"github.com/kataras/iris/macro/interpreter/lexer"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -31,6 +33,28 @@ func WildcardParam(name string) string {
|
||||
return prefix(name, WildcardParamStart)
|
||||
}
|
||||
|
||||
func convertTmplToNodePath(tmpl *macro.Template) string {
|
||||
routePath := tmpl.Src
|
||||
if len(tmpl.Params) > 0 {
|
||||
if routePath[len(routePath)-1] == '/' {
|
||||
routePath = routePath[0 : len(routePath)-2] // remove the last "/" if macro syntax instead of underline's.
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
Reference in New Issue
Block a user