1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-09 13:05:56 +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

@@ -19,50 +19,8 @@ type params struct {
func (p *params) resolve(index int, typ reflect.Type) (reflect.Value, bool) {
currentParamIndex := p.next
v, ok := resolveParam(currentParamIndex, typ)
v, ok := context.ParamResolverByTypeAndIndex(typ, currentParamIndex)
p.next = p.next + 1
return v, ok
}
func resolveParam(currentParamIndex int, typ reflect.Type) (reflect.Value, bool) {
var fn interface{}
switch typ.Kind() {
case reflect.Int:
fn = func(ctx context.Context) int {
// the second "ok/found" check is not necessary,
// because even if the entry didn't found on that "index"
// it will return an empty entry which will return the
// default value passed from the xDefault(def) because its `ValueRaw` is nil.
entry, _ := ctx.Params().GetEntryAt(currentParamIndex)
v, _ := entry.IntDefault(0)
return v
}
case reflect.Int64:
fn = func(ctx context.Context) int64 {
entry, _ := ctx.Params().GetEntryAt(currentParamIndex)
v, _ := entry.Int64Default(0)
return v
}
case reflect.Bool:
fn = func(ctx context.Context) bool {
entry, _ := ctx.Params().GetEntryAt(currentParamIndex)
v, _ := entry.BoolDefault(false)
return v
}
case reflect.String:
fn = func(ctx context.Context) string {
entry, _ := ctx.Params().GetEntryAt(currentParamIndex)
// print(entry.Key + " with index of: ")
// print(currentParamIndex)
// println(" and value: " + entry.String())
return entry.String()
}
default:
return reflect.Value{}, false
}
return reflect.ValueOf(fn), true
}