1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-18 02:17:05 +00:00

add '{date}' dynamic path parameter type

This commit is contained in:
Gerasimos (Makis) Maropoulos
2022-04-21 02:17:09 +03:00
parent 94447a2435
commit 90750d089d
7 changed files with 232 additions and 63 deletions

View File

@@ -5,6 +5,7 @@ import (
"reflect"
"strconv"
"strings"
"time"
"github.com/kataras/iris/v12/core/memstore"
)
@@ -240,6 +241,20 @@ var ParamResolvers = map[reflect.Type]func(paramIndex int) interface{}{
return ctx.Params().GetEntryAt(paramIndex).ValueRaw.(bool)
}
},
reflect.TypeOf(time.Time{}): func(paramIndex int) interface{} {
return func(ctx *Context) time.Time {
if ctx.Params().Len() <= paramIndex {
return unixEpochTime
}
v, ok := ctx.Params().GetEntryAt(paramIndex).ValueRaw.(time.Time)
if !ok {
return unixEpochTime
}
return v
}
},
}
// ParamResolverByTypeAndIndex will return a function that can be used to bind path parameter's exact value by its Go std type