mirror of
https://github.com/fosrl/newt.git
synced 2026-03-09 20:26:45 +00:00
Fix resolve
This commit is contained in:
20
util/util.go
20
util/util.go
@@ -14,6 +14,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func ResolveDomain(domain string) (string, error) {
|
func ResolveDomain(domain string) (string, error) {
|
||||||
|
// trim whitespace
|
||||||
|
domain = strings.TrimSpace(domain)
|
||||||
|
|
||||||
|
// Remove any protocol prefix if present (do this first, before splitting host/port)
|
||||||
|
domain = strings.TrimPrefix(domain, "http://")
|
||||||
|
domain = strings.TrimPrefix(domain, "https://")
|
||||||
|
|
||||||
|
// if there are any trailing slashes, remove them
|
||||||
|
domain = strings.TrimSuffix(domain, "/")
|
||||||
|
|
||||||
// Check if there's a port in the domain
|
// Check if there's a port in the domain
|
||||||
host, port, err := net.SplitHostPort(domain)
|
host, port, err := net.SplitHostPort(domain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -22,16 +32,6 @@ func ResolveDomain(domain string) (string, error) {
|
|||||||
port = ""
|
port = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove any protocol prefix if present
|
|
||||||
if strings.HasPrefix(host, "http://") {
|
|
||||||
host = strings.TrimPrefix(host, "http://")
|
|
||||||
} else if strings.HasPrefix(host, "https://") {
|
|
||||||
host = strings.TrimPrefix(host, "https://")
|
|
||||||
}
|
|
||||||
|
|
||||||
// if there are any trailing slashes, remove them
|
|
||||||
host = strings.TrimSuffix(host, "/")
|
|
||||||
|
|
||||||
// Lookup IP addresses
|
// Lookup IP addresses
|
||||||
ips, err := net.LookupIP(host)
|
ips, err := net.LookupIP(host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user