Add viper.GetDuration
diff --git a/README.md b/README.md
index a06bedb..9f236b2 100644
--- a/README.md
+++ b/README.md
@@ -212,6 +212,7 @@
* GetStringMapString(key string) : map[string]string
* GetStringSlice(key string) : []string
* GetTime(key string) : time.Time
+ * GetDuration(key string) : time.Duration
* IsSet(key string) : bool
One important thing to recognize is that each Get function will return
diff --git a/viper.go b/viper.go
index dda7091..e808887 100644
--- a/viper.go
+++ b/viper.go
@@ -267,6 +267,8 @@
return cast.ToFloat64(val)
case time.Time:
return cast.ToTime(val)
+ case time.Duration:
+ return cast.ToDuration(val)
case []string:
return val
}
@@ -298,6 +300,11 @@
return cast.ToTime(v.Get(key))
}
+func GetDuration(key string) time.Duration { return v.GetDuration(key) }
+func (v *viper) GetDuration(key string) time.Duration {
+ return cast.ToDuration(v.Get(key))
+}
+
func GetStringSlice(key string) []string { return v.GetStringSlice(key) }
func (v *viper) GetStringSlice(key string) []string {
return cast.ToStringSlice(v.Get(key))