diff --git a/cert.go b/cert.go index a5b712a..f2cf225 100644 --- a/cert.go +++ b/cert.go @@ -8,6 +8,7 @@ import ( "fmt" "io/ioutil" "net" + "net/url" "os" "path/filepath" "strings" @@ -77,6 +78,14 @@ func SetUserTempl(templ string) error { const defaultPort = "443" func SplitHostPort(hostport string) (string, string, error) { + if strings.Contains(hostport, "://") { + u, err := url.Parse(hostport) + if err != nil { + return "", "", err + } + fmt.Printf("u.Host: %s\n", u.Host) + hostport = u.Host + } if !strings.Contains(hostport, ":") { return hostport, defaultPort, nil } diff --git a/cert_test.go b/cert_test.go index 2b55917..bec8743 100644 --- a/cert_test.go +++ b/cert_test.go @@ -74,6 +74,8 @@ func TestSplitHostPort(t *testing.T) { {"smtp.example.com:465", want{"smtp.example.com", "465", ""}}, {"example.com:", want{"example.com", defaultPort, ""}}, {"example.com::", want{"", "", "address example.com::: too many colons in address"}}, + {"https://example.com", want{"example.com", defaultPort, ""}}, + {"https://example.com/path/to", want{"example.com", defaultPort, ""}}, } for _, test := range tests {