-
Notifications
You must be signed in to change notification settings - Fork 248
/
url.go
71 lines (56 loc) · 1.18 KB
/
url.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package parser
import (
"net/url"
strutil "github.com/torden/go-strutil"
)
// ValidateURL checks for a valid url
func ValidateURL(url string) bool {
/*
>>> https://google.com
<<< true
>>> google.com
<<< false
*/
if !strutil.NewStringValidator().IsValidURL(url) {
return false
}
return true
}
// ValidateDomain checks for a valid domain
func ValidateDomain(domain string) bool {
/*
>>> google.com
<<< true
>>> google
<<< false
*/
if !strutil.NewStringValidator().IsValidDomain(domain) {
return false
}
return true
}
// CreateURL will take in a valid domain and return the URL
func CreateURL(domain string) string {
/*
>>> google.com - Valid Domain
<<< https://google.com - Returned URL
*/
// concate nate https:// and the valid domain and return the now valid url
return "https://" + domain
}
// GetDomain takes in a valid URL and returns the domain of the url
func GetDomain(validurl string) string {
/*
>>> https://google.com - Valid URL
<<< google.com - Hostname
*/
// parse the url
u, err := url.Parse(validurl)
if err != nil {
panic(err)
}
// grab the hostname from the string
hostname := u.Hostname()
// hostname
return hostname
}