2022-08-25 23:55:55 +00:00
|
|
|
package url
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/url"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ParseURL parses the endpointURL using url.Parse.
|
|
|
|
//
|
|
|
|
// to prevent an error when url has port but no protocol prefix
|
|
|
|
// we add `//` prefix if needed
|
|
|
|
func ParseURL(endpointURL string) (*url.URL, error) {
|
2022-09-07 23:44:50 +00:00
|
|
|
if !strings.HasPrefix(endpointURL, "http") &&
|
|
|
|
!strings.HasPrefix(endpointURL, "tcp") &&
|
|
|
|
!strings.HasPrefix(endpointURL, "//") &&
|
|
|
|
!strings.HasPrefix(endpointURL, `unix:`) &&
|
|
|
|
!strings.HasPrefix(endpointURL, `npipe:`) {
|
2022-08-25 23:55:55 +00:00
|
|
|
endpointURL = fmt.Sprintf("//%s", endpointURL)
|
|
|
|
}
|
|
|
|
|
|
|
|
return url.Parse(endpointURL)
|
|
|
|
}
|