ttl.go 355 B

1234567891011121314151617181920
  1. package store
  2. import (
  3. "strconv"
  4. "time"
  5. )
  6. // Convert string duration to time format
  7. func TTL(duration string) (time.Time, error) {
  8. if duration != "" {
  9. duration, err := strconv.Atoi(duration)
  10. if err != nil {
  11. return Permanent, err
  12. }
  13. return time.Now().Add(time.Second * (time.Duration)(duration)), nil
  14. } else {
  15. return Permanent, nil
  16. }
  17. }