示例#1
0
// URLMustParse returns url.URL from static string. Don't use it with a dynamic param
func URLMustParse(s string) *url.URL {
	u, err := url.Parse(s)
	if err != nil {
		log.Errorf("Expected URL to parse: %q, got error: %v", s, err)
	}
	return u
}
示例#2
0
func getBaseURL(s string) (*url.URL, error) {
	u, err := url.Parse(s)
	if err != nil {
		return nil, err
	}

	return &url.URL{Scheme: u.Scheme, Host: u.Host}, nil
}
示例#3
0
func replaceBaseURL(oldURL string, baseURL url.URL) string {
	u, err := url.Parse(oldURL)
	if err != nil {
		return oldURL
	}

	u.Host = baseURL.Host
	u.Scheme = baseURL.Scheme
	if baseURL.Path != "" && baseURL.Path != "/" {
		u.Path = strings.TrimRight(baseURL.Path, "/") + u.Path
		u.RawPath = "" //remove RawPath to avoid differences with Path
	}
	return u.String()
}