capExpireTime make sure expire time is not too long or too short (if min or max is set)
(expire *time.Time, min, max time.Duration)
| 772 | |
| 773 | // capExpireTime make sure expire time is not too long or too short (if min or max is set) |
| 774 | func capExpireTime(expire *time.Time, min, max time.Duration) *time.Time { |
| 775 | timeNow := time.Now() |
| 776 | if expire == nil { |
| 777 | return nil |
| 778 | } |
| 779 | |
| 780 | cappedExpires := *expire |
| 781 | // Make sure expire time is not too long or too short |
| 782 | if min > 0 && expire.Before(timeNow.Add(min)) { |
| 783 | cappedExpires = timeNow.Add(min) |
| 784 | } else if max > 0 && expire.After(timeNow.Add(max)) { |
| 785 | cappedExpires = timeNow.Add(max) |
| 786 | } |
| 787 | |
| 788 | return &cappedExpires |
| 789 | } |
| 790 | |
| 791 | // checkPreconditions evaluates request preconditions and reports whether a precondition |
| 792 | // resulted in sending StatusNotModified or StatusPreconditionFailed. |