// fixURL massages the baseURL into a form needed for serving
// all pages correctly.
506030
func (sc *serverCmd) fixURL(cfg config.Provider, s string, port int) (string, error) {
	useLocalhost := false
	if s == "" {
		s = cfg.GetString("baseURL")
		useLocalhost = true
	}

	if !strings.HasSuffix(s, "/") {
		s = s + "/"
	}

	// do an initial parse of the input string
	u, err := url.Parse(s)
	if err != nil {
		return "", err
	}

	// if no Host is defined, then assume that no schema or double-slash were
	// present in the url.  Add a double-slash and make a best effort attempt.
	if u.Host == "" && s != "/" {
		s = "//" + s

		u, err = url.Parse(s)
		if err != nil {
			return "", err
		}
	}

	if useLocalhost {
		if u.Scheme == "https" {
			u.Scheme = "http"
		}
		u.Host = "localhost"
	}

	if sc.serverAppend {
		if strings.Contains(u.Host, ":") {
			u.Host, _, err = net.SplitHostPort(u.Host)
			if err != nil {
				return "", errors.Wrap(err, "Failed to split baseURL hostpost")
			}
		}
		u.Host += fmt.Sprintf(":%d", port)
	}

	return u.String(), nil
}
717250
func URL(url string) {
	switch def := dslengine.CurrentDefinition().(type) {
	case *design.ContactDefinition:
		def.URL = url
	case *design.LicenseDefinition:
		def.URL = url
	case *design.DocsDefinition:
		def.URL = url
	default:
		dslengine.IncompatibleDSL()
	}
}
779958
func (s *AliasService) buildURL() (string, url.Values, error) {
	path := "/_aliases"

	// Add query string parameters
	params := url.Values{}
	if s.pretty {
		params.Set("pretty", fmt.Sprintf("%v", s.pretty))
	}
	return path, params, nil
}
606000
func (a *Application) CharmURL() string {
	a.mu.Lock()
	defer a.mu.Unlock()
	return a.details.CharmURL
}
211666
func (s *AttachmentContent) SetUrl(v string) *AttachmentContent {
	s.Url = &v
	return s
}
964519
func (s *IdentityProviderDetails) SetUrl(v string) *IdentityProviderDetails {
	s.Url = &v
	return s
}
548617
func (bow *Browser) ResolveUrl(u *url.URL) *url.URL {
	return bow.Url().ResolveReference(u)
}
444342
func AbsURL(pageURL string, relURL string) string {
	if strings.Contains(relURL, `://`) {
		return relURL
	}
	urlInfo, err := url.Parse(pageURL)
	if err != nil {
		return ``
	}
	siteURL := urlInfo.Scheme + `://` + urlInfo.Host
	if strings.HasPrefix(relURL, `/`) {
		return siteURL + relURL
	}
	for strings.HasPrefix(relURL, `./`) {
		relURL = strings.TrimPrefix(relURL, `./`)
	}
	urlPath := path.Dir(urlInfo.Path)
	for strings.HasPrefix(relURL, `../`) {
		urlPath = path.Dir(urlPath)
		relURL = strings.TrimPrefix(relURL, `../`)
	}
	return siteURL + path.Join(urlPath, relURL)
}
709539
func (s *GCMMessage) SetUrl(v string) *GCMMessage {
	s.Url = &v
	return s
}
323457
func (s *Endpoint) SetUrl(v string) *Endpoint {
	s.Url = &v
	return s
}
154902
func (r *Request) BaseURL(uri string) *Request {
	r.Use(url.BaseURL(uri))
	return r
}
912574
func (s *HlsManifest) SetUrl(v string) *HlsManifest {
	s.Url = &v
	return s
}
1309588
func (a *SetBreakpointByURLArgs) SetURL(url string) *SetBreakpointByURLArgs {
	a.URL = &url
	return a
}
45033
func BuildURL(baseUrl string, queryValues url.Values) string {
	qryString := queryValues.Encode()
	if len(qryString) > 0 {
		return baseUrl + "?" + qryString
	}
	return baseUrl
}
179207
func (b *XMLBase) ResolveURL(u string) (string, error) {
	if b.CurrentBase() == "" {
		return u, nil
	}

	relURL, err := url.Parse(u)
	if err != nil {
		return u, err
	}
	curr := b.CurrentBaseURL()
	if curr.Path != "" && u != "" && curr.Path[len(curr.Path)-1] != '/' {
		// There's no reason someone would use a path in xml:base if they
		// didn't mean for it to be a directory
		curr.Path = curr.Path + "/"
	}
	absURL := b.CurrentBaseURL().ResolveReference(relURL)
	return absURL.String(), nil
}
1048993
func resourceURL(base *url.URL, relPath string) *url.URL {
	relPath, rawQuery := splitPathQuery(relPath)
	ref := &url.URL{Path: path.Join(base.Path, relPath), RawQuery: rawQuery}
	return base.ResolveReference(ref)
}
117725
func (s *RefreshService) buildURL() (string, url.Values, error) {
	var err error
	var path string

	if len(s.index) > 0 {
		path, err = uritemplates.Expand("/{index}/_refresh", map[string]string{
			"index": strings.Join(s.index, ","),
		})
	} else {
		path = "/_refresh"
	}
	if err != nil {
		return "", url.Values{}, err
	}

	// Add query string parameters
	params := url.Values{}
	if s.pretty {
		params.Set("pretty", fmt.Sprintf("%v", s.pretty))
	}
	return path, params, nil
}