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

made it work but looking for another approach

Former-commit-id: e61c4573543c57b8d6d4ef2583e40f52c391402f
This commit is contained in:
kataras
2017-12-04 05:06:03 +02:00
parent dd5de52f34
commit 7043f352d9
20 changed files with 855 additions and 792 deletions

View File

@@ -51,21 +51,14 @@ const (
ParamTypePath
)
// ValidKind will return true if at least one param type is supported
// for this std kind.
func ValidKind(k reflect.Kind) bool {
switch k {
case reflect.String:
fallthrough
case reflect.Int:
fallthrough
case reflect.Int64:
fallthrough
case reflect.Bool:
return true
default:
return false
func (pt ParamType) String() string {
for k, v := range paramTypes {
if v == pt {
return k
}
}
return "unexpected"
}
// Not because for a single reason
@@ -96,6 +89,23 @@ func (pt ParamType) Kind() reflect.Kind {
return reflect.Invalid // 0
}
// ValidKind will return true if at least one param type is supported
// for this std kind.
func ValidKind(k reflect.Kind) bool {
switch k {
case reflect.String:
fallthrough
case reflect.Int:
fallthrough
case reflect.Int64:
fallthrough
case reflect.Bool:
return true
default:
return false
}
}
// Assignable returns true if the "k" standard type
// is assignabled to this ParamType.
func (pt ParamType) Assignable(k reflect.Kind) bool {
@@ -133,6 +143,30 @@ func LookupParamType(ident string) ParamType {
return ParamTypeUnExpected
}
// LookupParamTypeFromStd accepts the string representation of a standard go type.
// It returns a ParamType, but it may differs for example
// the alphabetical, file, path and string are all string go types, so
// make sure that caller resolves these types before this call.
//
// string matches to string
// int matches to int
// int64 matches to long
// bool matches to boolean
func LookupParamTypeFromStd(goType string) ParamType {
switch goType {
case "string":
return ParamTypeString
case "int":
return ParamTypeInt
case "int64":
return ParamTypeLong
case "bool":
return ParamTypeBoolean
default:
return ParamTypeUnExpected
}
}
// ParamStatement is a struct
// which holds all the necessary information about a macro parameter.
// It holds its type (string, int, alphabetical, file, path),

View File

@@ -2,6 +2,7 @@ package router
import (
"github.com/kataras/iris/context"
"github.com/kataras/iris/core/errors"
"github.com/kataras/iris/core/router/macro"
"github.com/kataras/iris/mvc/activator"
)
@@ -14,6 +15,8 @@ import (
//
// Look the "APIBuilder" for its implementation.
type Party interface {
// GetReporter returns the reporter for adding errors
GetReporter() *errors.Reporter
// Macros returns the macro map which is responsible
// to register custom macro functions for all routes.
//

View File

@@ -23,7 +23,7 @@ type Route struct {
// Handlers are the main route's handlers, executed by order.
// Cannot be empty.
Handlers context.Handlers
mainHandlerName string
MainHandlerName string
// temp storage, they're appended to the Handlers on build.
// Execution happens after Begin and main Handler(s), can be empty.
doneHandlers context.Handlers
@@ -61,7 +61,7 @@ func NewRoute(method, subdomain, unparsedPath, mainHandlerName string,
tmpl: tmpl,
Path: path,
Handlers: handlers,
mainHandlerName: mainHandlerName,
MainHandlerName: mainHandlerName,
FormattedPath: formattedPath,
}
return route, nil
@@ -214,12 +214,12 @@ func (r Route) Trace() string {
}
printfmt += fmt.Sprintf(" %s ", r.Tmpl().Src)
if l := len(r.Handlers); l > 1 {
printfmt += fmt.Sprintf("-> %s() and %d more", r.mainHandlerName, l-1)
printfmt += fmt.Sprintf("-> %s() and %d more", r.MainHandlerName, l-1)
} else {
printfmt += fmt.Sprintf("-> %s()", r.mainHandlerName)
printfmt += fmt.Sprintf("-> %s()", r.MainHandlerName)
}
// printfmt := fmt.Sprintf("%s: %s >> %s", r.Method, r.Subdomain+r.Tmpl().Src, r.mainHandlerName)
// printfmt := fmt.Sprintf("%s: %s >> %s", r.Method, r.Subdomain+r.Tmpl().Src, r.MainHandlerName)
// if l := len(r.Handlers); l > 0 {
// printfmt += fmt.Sprintf(" and %d more", l)
// }