mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-23 14:50:24 +00:00
23 lines
431 B
Go
23 lines
431 B
Go
|
package defaults
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func SetDurationFromEnv(getDurationFromEnv func(string) string, varSetter func(time.Duration), name string) {
|
||
|
durationFromEnv := getDurationFromEnv(name)
|
||
|
|
||
|
if len(durationFromEnv) == 0 {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
duration, err := time.ParseDuration(durationFromEnv)
|
||
|
|
||
|
if err != nil {
|
||
|
panic(fmt.Sprintf("Expected a duration when using %s! Parse error %v", name, err))
|
||
|
}
|
||
|
|
||
|
varSetter(duration)
|
||
|
}
|