github.com/avenga/couper@v1.12.2/config/duration.go (about)

     1  package config
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  )
     7  
     8  func ParseDuration(attribute string, value string, _default time.Duration) (time.Duration, error) {
     9  	if value == "" {
    10  		return _default, nil
    11  	}
    12  
    13  	duration, err := time.ParseDuration(value)
    14  	if err != nil {
    15  		return 0, fmt.Errorf("%s: %s", attribute, err)
    16  	}
    17  	if duration < 0 {
    18  		return 0, fmt.Errorf("%s: cannot be negative: '%s'", attribute, value)
    19  	}
    20  
    21  	return duration, nil
    22  }