mirror of
https://github.com/aykhans/slash-e.git
synced 2025-07-04 04:23:16 +00:00
chore: add location header
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
||||
"crypto/rand"
|
||||
"math/big"
|
||||
"net/mail"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@ -55,3 +56,9 @@ func RandomString(n int) (string, error) {
|
||||
}
|
||||
return sb.String(), nil
|
||||
}
|
||||
|
||||
// ValidateURI validates the URI.
|
||||
func ValidateURI(uri string) bool {
|
||||
u, err := url.Parse(uri)
|
||||
return err == nil && u.Scheme != "" && u.Host != ""
|
||||
}
|
||||
|
@ -29,3 +29,33 @@ func TestValidateEmail(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateURI(t *testing.T) {
|
||||
tests := []struct {
|
||||
uri string
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
uri: "https://localhsot:3000",
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
uri: "https://yourselfhosted.com",
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
uri: "google.com",
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
uri: "i don't know",
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
result := ValidateURI(test.uri)
|
||||
if result != test.want {
|
||||
t.Errorf("Validate URI %s: got result %v, want %v.", test.uri, result, test.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user