1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-06 19:47:05 +00:00

new {weekday} path parameter type

This commit is contained in:
kataras
2022-06-23 23:01:52 +03:00
parent 999e83723b
commit 8bfea48cd6
6 changed files with 146 additions and 12 deletions

View File

@@ -17,18 +17,6 @@ type RequestParams struct {
memstore.Store
}
// RequestParamsReadOnly is the read-only access type of RequestParams.
type RequestParamsReadOnly interface {
Get(key string) string
GetEntryAt(index int) memstore.Entry
Visit(visitor func(key string, value string))
GetTrim(key string) string
GetEscape(key string) string
GetDecoded(key string) string
} // Note: currently unused.
var _ RequestParamsReadOnly = (*RequestParams)(nil)
// Set inserts a parameter value.
// See `Get` too.
func (r *RequestParams) Set(key, value string) {
@@ -253,6 +241,20 @@ var ParamResolvers = map[reflect.Type]func(paramIndex int) interface{}{
return unixEpochTime
}
return v
}
},
reflect.TypeOf(time.Weekday(0)): func(paramIndex int) interface{} {
return func(ctx *Context) time.Weekday {
if ctx.Params().Len() <= paramIndex {
return time.Sunday
}
v, ok := ctx.Params().GetEntryAt(paramIndex).ValueRaw.(time.Weekday)
if !ok {
return time.Sunday
}
return v
}
},