Пример #1
0
func probeHgUrl(schemes []string, host, path string, insecure bool) (string, error) {
	for _, scheme := range schemes {
		switch scheme {
		case "https":
			url := scheme + "://" + host + "/" + path
			if _, err := run("hg", "identify", url); err == nil {
				return url, nil
			}
		case "http", "git":
			url := scheme + "://" + host + "/" + path
			if !insecure {
				gb.Infof("skipping insecure protocol: %v", url)
			} else {
				if _, err := run("hg", "identify", url); err == nil {
					return url, nil
				}
			}
		}
	}
	return "", fmt.Errorf("unable to determine remote protocol")
}
Пример #2
0
func fetchMetadata(scheme, path string, insecure bool) (io.ReadCloser, error) {
	url := fmt.Sprintf("%s://%s?go-get=1", scheme, path)
	switch scheme {
	case "https":
		resp, err := http.Get(url)
		if err == nil {
			return resp.Body, nil
		}
	case "http":
		if !insecure {
			gb.Infof("skipping insecure protocol: %v", url)
		} else {
			resp, err := http.Get(url)
			if err == nil {
				return resp.Body, nil
			}
		}
	}

	return nil, fmt.Errorf("unknown remote protocol scheme: %q", scheme)
}