mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-14 04:26:32 +00:00
26 lines
353 B
Go
26 lines
353 B
Go
|
package common
|
||
|
|
||
|
import (
|
||
|
"net"
|
||
|
"net/url"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
func ExtractHostFromCloneURL(cloneURL string) (string, error) {
|
||
|
u, err := url.Parse(cloneURL)
|
||
|
if err != nil {
|
||
|
return "", err
|
||
|
}
|
||
|
|
||
|
if !strings.Contains(u.Host, ":") {
|
||
|
return u.Host, nil
|
||
|
}
|
||
|
|
||
|
host, _, err := net.SplitHostPort(u.Host)
|
||
|
if err != nil {
|
||
|
return "", err
|
||
|
}
|
||
|
|
||
|
return host, nil
|
||
|
}
|