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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user