-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
30 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package util | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"net/url" | ||
|
||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
// ValidateUrl checks if a string URL can be parsed and if it has a valid scheme. | ||
func ValidateUrl(input string) error { | ||
url, err := url.Parse(input) | ||
if err != nil { | ||
log.Error().Err(err).Msg("Unable to parse url input error") | ||
return err | ||
} | ||
|
||
if url.Scheme == "" { | ||
return errors.New("the scheme has not been specified") | ||
} | ||
switch url.Scheme { | ||
case "http", "https", "ws", "wss": | ||
return nil | ||
default: | ||
return fmt.Errorf("the scheme '%s' is not supported", url.Scheme) | ||
} | ||
} |