aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/go-viper/mapstructure/v2/decode_hooks.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/go-viper/mapstructure/v2/decode_hooks.go')
-rw-r--r--vendor/github.com/go-viper/mapstructure/v2/decode_hooks.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/vendor/github.com/go-viper/mapstructure/v2/decode_hooks.go b/vendor/github.com/go-viper/mapstructure/v2/decode_hooks.go
index 2523c6ad9..1f3c69d4b 100644
--- a/vendor/github.com/go-viper/mapstructure/v2/decode_hooks.go
+++ b/vendor/github.com/go-viper/mapstructure/v2/decode_hooks.go
@@ -6,6 +6,7 @@ import (
"fmt"
"net"
"net/netip"
+ "net/url"
"reflect"
"strconv"
"strings"
@@ -176,6 +177,26 @@ func StringToTimeDurationHookFunc() DecodeHookFunc {
}
}
+// StringToURLHookFunc returns a DecodeHookFunc that converts
+// strings to *url.URL.
+func StringToURLHookFunc() DecodeHookFunc {
+ return func(
+ f reflect.Type,
+ t reflect.Type,
+ data interface{},
+ ) (interface{}, error) {
+ if f.Kind() != reflect.String {
+ return data, nil
+ }
+ if t != reflect.TypeOf(&url.URL{}) {
+ return data, nil
+ }
+
+ // Convert it by parsing
+ return url.Parse(data.(string))
+ }
+}
+
// StringToIPHookFunc returns a DecodeHookFunc that converts
// strings to net.IP
func StringToIPHookFunc() DecodeHookFunc {