diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-08-10 13:12:14 +0200 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-08-10 13:12:14 +0200 |
| commit | 589ed2202dcfe3ae8669ef2e70eea6a482f195e4 (patch) | |
| tree | 3f9bf0c2aec302f27fe596943555fe57e0486237 /internal/util/util.go | |
| parent | 94d3308eec4288d3ec1bb6f97c226e9f51785ca1 (diff) | |
State + Util: Create a valid URL by ensuring a scheme is present
Diffstat (limited to 'internal/util/util.go')
| -rw-r--r-- | internal/util/util.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/internal/util/util.go b/internal/util/util.go index b86e4cb..17ae1c3 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -11,6 +11,18 @@ import ( "github.com/jwijenbergh/eduvpn-common/internal/types" ) +func EnsureValidURL(s string) (string, error) { + parsedURL, parseErr := url.Parse(s) + if parseErr != nil { + return "", &types.WrappedErrorMessage{Message: fmt.Sprintf("failed parsing url: %s", s), Err: parseErr} + } + + if parsedURL.Scheme == "" { + parsedURL.Scheme = "https" + } + return parsedURL.String(), nil +} + // Creates a random byteslice of `size` func MakeRandomByteSlice(size int) ([]byte, error) { byteSlice := make([]byte, size) |
