27 lines
542 B
Go
27 lines
542 B
Go
package link
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
)
|
|
|
|
func ValidateHTTPURL(value string) error {
|
|
parsed, err := url.Parse(value)
|
|
if err != nil {
|
|
return fmt.Errorf("must be a valid URL")
|
|
}
|
|
if parsed.Scheme != "http" && parsed.Scheme != "https" {
|
|
return fmt.Errorf("must use http or https")
|
|
}
|
|
if parsed.Host == "" {
|
|
return fmt.Errorf("must include a host")
|
|
}
|
|
if parsed.RawQuery != "" {
|
|
return fmt.Errorf("must not include a query string")
|
|
}
|
|
if parsed.Fragment != "" {
|
|
return fmt.Errorf("must not include a fragment")
|
|
}
|
|
return nil
|
|
}
|