Exemplo n.º 1
0
func fetchCandidates(can *resolver.Candidates, url string) error {
	for _, comp := range compressions {
		resp, err := http.Get(url + comp)
		if err != nil {
			return err
		}
		if resp.StatusCode != http.StatusOK {
			resp.Body.Close()
			continue
		}
		defer resp.Body.Close()
		switch comp {
		case ".xz":
			reader, err := xz.NewReader(resp.Body, 0)
			if err != nil {
				return err
			}
			return can.AppendBinaryIndexReader(reader)
		case ".bz2":
			return can.AppendBinaryIndexReader(bzip2.NewReader(resp.Body))
		case ".gz":
			reader, err := gzip.NewReader(resp.Body)
			if err != nil {
				return err
			}
			defer reader.Close()
			return can.AppendBinaryIndexReader(reader)
		}
		return can.AppendBinaryIndexReader(resp.Body)
	}
	return fmt.Errorf("unable to find %s (tried all of %q)", url, compressions)
}