// readURL attempts to read a file from an url.
// This is slightly adapted from https://github.com/helm/helm/blob/2332b480c9cb70a0d8a85247992d6155fbe82416/cmd/helm/install.go#L552
323924
func readURL(URL string) ([]byte, error) {
	var settings helmenv.EnvSettings
	flags := pflag.NewFlagSet("helm-env", pflag.ContinueOnError)
	settings.AddFlags(flags)
	settings.Init(flags)

	u, _ := url.Parse(URL)
	p := getter.All(settings)

	getterConstructor, err := p.ByScheme(u.Scheme)

	if err != nil {
		return []byte{}, err
	}

	getter, err := getterConstructor(URL, "", "", "")
	if err != nil {
		return []byte{}, err
	}
	data, err := getter.Get(URL)
	return data.Bytes(), err
}
805417
func ParseURL(s string) (u *url.URL, err error) {
	if u, err = url.Parse(s); err != nil {
		return
	}
	if err = UpdateURL(u); err != nil {
		u = nil
	}
	return u, err
}
14203
func (s *ClearScrollService) buildURL() (string, url.Values, error) {
	path, err := uritemplates.Expand("/_search/scroll", map[string]string{})
	if err != nil {
		return "", url.Values{}, err
	}
	return path, url.Values{}, nil
}
1033967
func (m *Metadata) DownloadURL() (*url.URL, error) {
	if m.BaseURL == "" {
		m.BaseURL = imagemetadata.UbuntuCloudImagesURL
	}
	u, err := url.Parse(m.BaseURL + "/" + m.Path)
	if err != nil {
		return nil, errors.Annotate(err, "failed to create url")
	}
	return u, nil
}
862783
func (h *HTTP) gatherURL(
	acc telegraf.Accumulator,
	url string,
) error {
	body, err := makeRequestBodyReader(h.ContentEncoding, h.Body)
	if err != nil {
		return err
	}

	request, err := http.NewRequest(h.Method, url, body)
	if err != nil {
		return err
	}

	if h.ContentEncoding == "gzip" {
		request.Header.Set("Content-Encoding", "gzip")
	}

	for k, v := range h.Headers {
		if strings.ToLower(k) == "host" {
			request.Host = v
		} else {
			request.Header.Add(k, v)
		}
	}

	if h.Username != "" || h.Password != "" {
		request.SetBasicAuth(h.Username, h.Password)
	}

	resp, err := h.client.Do(request)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	if resp.StatusCode != http.StatusOK {
		return fmt.Errorf("Received status code %d (%s), expected %d (%s)",
			resp.StatusCode,
			http.StatusText(resp.StatusCode),
			http.StatusOK,
			http.StatusText(http.StatusOK))
	}

	b, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return err
	}

	metrics, err := h.parser.Parse(b)
	if err != nil {
		return err
	}

	for _, metric := range metrics {
		if !metric.HasTag("url") {
			metric.AddTag("url", url)
		}
		acc.AddFields(metric.Name(), metric.Fields(), metric.Tags(), metric.Time())
	}

	return nil
}
76413
func (s *IndicesGetService) buildURL() (string, url.Values, error) {
	var err error
	var path string
	var index []string

	if len(s.index) > 0 {
		index = s.index
	} else {
		index = []string{"_all"}
	}

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

	// Add query string parameters
	params := url.Values{}
	if s.pretty {
		params.Set("pretty", "1")
	}
	if s.expandWildcards != "" {
		params.Set("expand_wildcards", s.expandWildcards)
	}
	if s.local != nil {
		params.Set("local", fmt.Sprintf("%v", *s.local))
	}
	if s.ignoreUnavailable != nil {
		params.Set("ignore_unavailable", fmt.Sprintf("%v", *s.ignoreUnavailable))
	}
	if s.allowNoIndices != nil {
		params.Set("allow_no_indices", fmt.Sprintf("%v", *s.allowNoIndices))
	}
	return path, params, nil
}
454070
func (reader *PluginConfigReader) GetURL(key string, defaultValue string) *url.URL {
	value, err := reader.WithError.GetURL(key, defaultValue)
	reader.Errors.Push(err)
	return value
}
471957
func ResolveUrl(url *url.URL) (*url.URL, error) {
	if url.Scheme == "file" || url.Scheme == "socket" || url.Scheme == "unix" {
		return utilUrl.Copy(url), nil
	}
	if len(url.Host) > 0 && url.Host[0] == '/' {
		return utilUrl.Copy(url), nil
	}
	if len(url.Host) >= 3 && url.Host[1] == ':' && url.Host[2] == '/' {
		return utilUrl.Copy(url), nil
	}

	mysqlNotation := regExpResolveUrl.FindAllString(url.Host, 1)
	if len(mysqlNotation) >= 1 {
		return utilUrl.Copy(url), nil
	}

	out := utilUrl.Copy(url)

	host, err := Resolve(url.Host)
	if err != nil {
		return nil, e.Forward(err)
	}
	out.Host = host
	return out, nil
}
1262799
func (p *PullRequest) GetURL() string {
	if p == nil || p.URL == nil {
		return ""
	}
	return *p.URL
}
883428
func (ld *logData) viewerURL() string {
	for _, s := range ld.logStreams {
		desc, err := s.DescriptorValue()
		if err != nil {
			continue
		}
		if u, ok := desc.Tags["logdog.viewer_url"]; ok {
			return u
		}
	}
	return ""
}
44704
func URL(c CloneURL, path string) *Resource {
	r := &Resource{u: c.URL()}
	r.u.Path = Path + path
	return r
}
174273
func (s *storageSimpleStreamsDataSource) URL(path string) (string, error) {
	return s.storage.URL(s.relpath(path))
}
886387
func (d *Deployment) GetURL() string {
	if d == nil || d.URL == nil {
		return ""
	}
	return *d.URL
}
788033
func (h *Hook) GetURL() string {
	if h == nil || h.URL == nil {
		return ""
	}
	return *h.URL
}
113445
func (mbs maybeSources) getURL() string {
	strslice := make([]string, 0, len(mbs))
	for _, mb := range mbs {
		strslice = append(strslice, mb.getURL())
	}
	return strings.Join(strslice, "\n")
}
1285983
func (r *RepositoryContent) GetURL() string {
	if r == nil || r.URL == nil {
		return ""
	}
	return *r.URL
}
161214
func (s *StreamAddr) URL() *url.URL {
	return &url.URL{
		Scheme: logDogURLScheme,
		Host:   s.Host,
		Path:   strings.Join([]string{"", string(s.Project), string(s.Path)}, "/"),
	}
}