2020-07-16 10:57:28 +02:00
|
|
|
package executer
|
2020-04-04 15:59:05 +05:30
|
|
|
|
2020-08-25 23:24:31 +02:00
|
|
|
import "net/url"
|
2020-04-04 15:59:05 +05:30
|
|
|
|
2020-04-22 22:45:02 +02:00
|
|
|
// isURL tests a string to determine if it is a well-structured url or not.
|
|
|
|
|
func isURL(toTest string) bool {
|
|
|
|
|
_, err := url.ParseRequestURI(toTest)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u, err := url.Parse(toTest)
|
|
|
|
|
if err != nil || u.Scheme == "" || u.Host == "" {
|
|
|
|
|
return false
|
|
|
|
|
}
|
2020-08-25 23:24:31 +02:00
|
|
|
|
2020-04-22 22:45:02 +02:00
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-26 05:50:33 +05:30
|
|
|
// extractDomain extracts the domain name of a URL
|
2020-08-25 23:24:31 +02:00
|
|
|
func extractDomain(theURL string) string {
|
|
|
|
|
u, err := url.Parse(theURL)
|
2020-04-24 15:19:43 +02:00
|
|
|
if err != nil {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
2020-08-25 23:24:31 +02:00
|
|
|
|
2020-04-26 05:50:33 +05:30
|
|
|
hostname := u.Hostname()
|
2020-04-24 15:19:43 +02:00
|
|
|
|
2020-08-25 23:24:31 +02:00
|
|
|
return hostname
|
2020-04-22 22:45:02 +02:00
|
|
|
}
|