summaryrefslogtreecommitdiff
path: root/internal/util
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-08-10 13:12:14 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-08-10 13:12:14 +0200
commit589ed2202dcfe3ae8669ef2e70eea6a482f195e4 (patch)
tree3f9bf0c2aec302f27fe596943555fe57e0486237 /internal/util
parent94d3308eec4288d3ec1bb6f97c226e9f51785ca1 (diff)
State + Util: Create a valid URL by ensuring a scheme is present
Diffstat (limited to 'internal/util')
-rw-r--r--internal/util/util.go12
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)