| 152 | } |
| 153 | |
| 154 | func parseRetryAfter(value string, now time.Time) (time.Duration, bool) { |
| 155 | value = strings.TrimSpace(value) |
| 156 | if value == "" { |
| 157 | return 0, false |
| 158 | } |
| 159 | |
| 160 | if seconds, err := strconv.ParseInt(value, 10, 64); err == nil && seconds >= 0 { |
| 161 | return time.Duration(seconds) * time.Second, true |
| 162 | } |
| 163 | |
| 164 | retryAt, err := http.ParseTime(value) |
| 165 | if err != nil { |
| 166 | return 0, false |
| 167 | } |
| 168 | if retryAt.Before(now) { |
| 169 | return 0, true |
| 170 | } |
| 171 | return retryAt.Sub(now), true |
| 172 | } |
| 173 | |
| 174 | // sortedInstances converts a map keyed by ID into a sorted slice. |
| 175 | func sortedInstances(raw map[string]Instance) []Instance { |