mirror of
https://github.com/kataras/iris.git
synced 2026-01-10 05:25:58 +00:00
add the ability to add custom parameter types to the interpreter and mapped macros with any number of macro functions - example added - although it's working it is not ready yet - I have to do some cleanup, doc comments and a TODO
Former-commit-id: 8ac751b649a3b8e59948fd4c89ad53d25f49d0d5
This commit is contained in:
@@ -19,64 +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.ParamResolverByKindAndIndex(typ.Kind(), 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.Uint8:
|
||||
fn = func(ctx context.Context) uint8 {
|
||||
entry, _ := ctx.Params().GetEntryAt(currentParamIndex)
|
||||
v, _ := entry.Uint8Default(0)
|
||||
|
||||
return v
|
||||
}
|
||||
case reflect.Uint64:
|
||||
fn = func(ctx context.Context) uint64 {
|
||||
entry, _ := ctx.Params().GetEntryAt(currentParamIndex)
|
||||
v, _ := entry.Uint64Default(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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user