1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-18 01:15:59 +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

@@ -700,6 +700,25 @@ func (e Entry) TimeDefault(def time.Time) (time.Time, error) {
return vv, nil
}
var weekdayType = reflect.TypeOf(time.Weekday(0))
// WeekdayDefault returns the stored time.Weekday value based on its "key".
// If does not exist or the stored key's value is not a weekday
// it returns the "def" weekday value and a not found error.
func (e Entry) WeekdayDefault(def time.Weekday) (time.Weekday, error) {
v := e.ValueRaw
if v == nil {
return def, e.notFound(weekdayType)
}
vv, ok := v.(time.Weekday)
if !ok {
return def, nil
}
return vv, nil
}
// Value returns the value of the entry,
// respects the immutable.
func (e Entry) Value() interface{} {
@@ -1184,6 +1203,20 @@ func (r *Store) SimpleDate(key string) string {
return tt.Format(simpleDateLayout)
}
const zeroWeekday = time.Sunday
// GetWeekday returns the stored time.Weekday value based on its "key".
// If does not exist or the stored key's value is not a weekday
// it returns the time.Sunday value and a not found error.
func (r *Store) GetWeekday(key string) (time.Weekday, error) {
v, ok := r.GetEntry(key)
if !ok {
return zeroWeekday, v.notFound(timeType)
}
return v.WeekdayDefault(zeroWeekday)
}
// Remove deletes an entry linked to that "key",
// returns true if an entry is actually removed.
func (r *Store) Remove(key string) bool {