(name string)
| 46 | } |
| 47 | |
| 48 | func lifetimeFromEnv(name string) o.Option[time.Duration] { |
| 49 | raw, ok := os.LookupEnv(name) |
| 50 | if !ok { |
| 51 | return o.None[time.Duration]() |
| 52 | } |
| 53 | seconds, err := strconv.ParseInt(raw, 10, 64) |
| 54 | if err != nil { |
| 55 | panic(fmt.Errorf("%s: %w", name, err)) |
| 56 | } |
| 57 | if seconds > math.MaxInt64/int64(time.Second) || seconds < math.MinInt64/int64(time.Second) { |
| 58 | panic(fmt.Errorf("%s: lifetime in seconds overflows time.Duration", name)) |
| 59 | } |
| 60 | return o.Some(time.Duration(seconds) * time.Second) |
| 61 | } |
no test coverage detected