yay/pkg/download/aur.go

38 lines
727 B
Go
Raw Normal View History

2020-12-15 01:29:05 +01:00
package download
import (
"errors"
"io/ioutil"
"net/http"
"net/url"
2021-01-30 12:52:50 +01:00
"github.com/leonelquinteros/gotext"
2020-12-15 01:29:05 +01:00
)
2021-01-30 12:52:50 +01:00
var AURPackageURL = "https://aur.archlinux.org/cgit/aur.git"
2020-12-15 01:29:05 +01:00
2021-01-30 12:52:50 +01:00
var ErrAURPackageNotFound = errors.New(gotext.Get("package not found in AUR"))
2020-12-15 01:29:05 +01:00
2021-01-30 12:52:50 +01:00
func GetAURPkgbuild(httpClient *http.Client, pkgName string) ([]byte, error) {
2020-12-15 01:29:05 +01:00
values := url.Values{}
values.Set("h", pkgName)
2021-01-30 12:52:50 +01:00
pkgURL := AURPackageURL + "/plain/PKGBUILD?" + values.Encode()
2020-12-15 01:29:05 +01:00
2021-01-30 12:52:50 +01:00
resp, err := httpClient.Get(pkgURL)
2020-12-15 01:29:05 +01:00
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
return nil, ErrAURPackageNotFound
}
defer resp.Body.Close()
pkgBuild, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return pkgBuild, nil
}