// parseURL ensures error if parse error or no url was returned from url.Parse
513532
func parseURL(urlString string) (*url.URL, error) {
	url, parseErr := url.Parse(urlString)
	if parseErr != nil {
		return nil, parseErr
	}
	if url == nil {
		return nil, fmt.Errorf("No URL")
	}
	return url, nil
}
691006
func Parse(i string) (o *url.URL, err error) {
	// Basic parse
	if o, err = url.Parse(i); err != nil {
		err = errors.Wrapf(err, "basic parsing of url %s failed", i)
		return
	}

	// File
	if o.Scheme == "" {
		// Get absolute path
		if i, err = filepath.Abs(i); err != nil {
			err = errors.Wrapf(err, "getting absolute path of %s failed", i)
			return
		}

		// Set url
		o = &url.URL{Path: filepath.ToSlash(i), Scheme: "file"}
	}
	return
}
1070411
func IsURL(u string) bool {
	var parsedURL *url.URL
	var err error

	parsedURL, err = url.ParseRequestURI(u)
	if err == nil {
		if parsedURL != nil && parsedURL.Host != "" {
			return true
		}
	}
	return false
}
454070
func (reader *PluginConfigReader) GetURL(key string, defaultValue string) *url.URL {
	value, err := reader.WithError.GetURL(key, defaultValue)
	reader.Errors.Push(err)
	return value
}
1332422
func (i *Issue) GetURL() string {
	if i == nil || i.URL == nil {
		return ""
	}
	return *i.URL
}
376269
func (u *URL) Parse(ref string) (*URL, error) {
	refurl, err := Parse(ref)
	if err != nil {
		return nil, err
	}
	return u.ResolveReference(refurl), nil
}
1340283
func normalizeURL(addr string) (*url.URL, error) {
	addr = strings.TrimSpace(addr)

	u, err := url.Parse(addr)
	if err != nil {
		return nil, err
	}

	if u.Opaque != "" {
		u.Host = net.JoinHostPort(u.Scheme, u.Opaque)
		u.Opaque = ""
	} else if u.Path != "" && !strings.Contains(u.Path, ":") {
		u.Host = net.JoinHostPort(u.Path, "8888")
		u.Path = ""
	} else if u.Scheme == "" {
		u.Host = u.Path
		u.Path = ""
	}

	if u.Scheme != "https" {
		u.Scheme = "http"
	}

	_, port, err := net.SplitHostPort(u.Host)
	if err != nil {
		_, port, err = net.SplitHostPort(u.Host + ":8888")
		if err != nil {
			return nil, err
		}
	}

	if port != "" {
		_, err = strconv.Atoi(port)
		if err != nil {
			return nil, err
		}
	}
	return u, nil
}
521661
func URL() string {
	url := "http" + RandString([]string{"s", ""}) + "://www."
	url += DomainName()

	// Slugs
	num := Number(1, 4)
	slug := make([]string, num)
	for i := 0; i < num; i++ {
		slug[i] = BS()
	}
	url += "/" + strings.ToLower(strings.Join(slug, "/"))

	return url
}
878045
func ParseURL(scheme, host, path string) *url.URL {
	u, err := url.Parse(fmt.Sprintf("%s://%s/%s", scheme, host, strings.TrimPrefix(path, "/")))
	if err != nil {
		u = &url.URL{
			Scheme: scheme,
			Host:   host,
			Path:   path,
		}
	}
	return u
}
1262799
func (p *PullRequest) GetURL() string {
	if p == nil || p.URL == nil {
		return ""
	}
	return *p.URL
}
1051542
func (tokenizer *Tokenizer) parseUri() (string, error) {
	start := tokenizer.scanner.Index()
	tokenizer.scanner.Advance()
	for tokenizer.CanRead() {
		if tokenizer.scanner.Char() == '>' {
			uri := tokenizer.scanner.Substring(start, tokenizer.scanner.Index()+1)
			return uri, nil
		}
		if !tokenizer.isUriChar() {
			return "", tokenizer.Error("Invalid character in URI")
		}
		tokenizer.scanner.Advance()
	}
	return "", tokenizer.Error("URI did not end with >")
}
516630
func NormalizeURL(u *url.URL, f NormalizationFlags) string {
	for _, k := range flagsOrder {
		if f&k == k {
			flags[k](u)
		}
	}
	return urlesc.Escape(u)
}
568317
func (resp *Response) URL() (*url.URL, error) {
	u := resp.Request.URL
	switch resp.StatusCode {
	case http.StatusMovedPermanently, http.StatusFound,
		http.StatusSeeOther, http.StatusTemporaryRedirect:
		location, err := resp.Location()
		if err != nil {
			return nil, err
		}
		u = u.ResolveReference(location)
	}
	return u, nil
}
740758
func (parser *Parser) ParseUrl(url string) error {
	if !parser.initialised {
		if err := parser.init(); err != nil {
			return err
		}
	}

	response, err := http.Get(url)

	if err != nil {
		return err
	}

	defer response.Body.Close()
	contents, err := ioutil.ReadAll(response.Body)

	if err != nil {
		return err
	}

	return parser.rt.run(string(contents))
}
869762
func FixURL(url *string) error {
	if *url == "" {
		return fmt.Errorf("Incorrect url '%v'", url)
	}
	if strings.HasPrefix(*url, "http://") || strings.HasPrefix(*url, "https://") {
		return nil
	}
	*url = "http://" + *url
	return nil
}
941000
func ParseProxyURL(proxy string) (*url.URL, error) {
	proxyURL, err := url.Parse(proxy)

	// logic copied from net/http.ProxyFromEnvironment
	if err != nil || !strings.HasPrefix(proxyURL.Scheme, "http") {
		// proxy was bogus. Try prepending "http://" to it and see if that
		// parses correctly. If not, we fall through and complain about the
		// original one.
		if proxyURL, err := url.Parse("http://" + proxy); err == nil {
			return proxyURL, nil
		}
	}

	return proxyURL, err
}
605654
func (s *Server) URL() (u *url.URL, err error) {
	if s.Scheme == "" {
		return u, fmt.Errorf("Server %s:%d has no scheme, cannot make a URL", s.Host, s.Port)
	}

	ustring := fmt.Sprintf("%s://%s:%d", s.Scheme, s.Host, s.Port)

	u, err = url.Parse(ustring)
	if err != nil {
		return u, fmt.Errorf("Could not parse %s: %s", ustring, err)
	}

	return
}