feat: return complete repo info
This commit is contained in:
parent
0f799b0d5a
commit
d089ad4931
@ -13,17 +13,10 @@ import (
|
||||
"golang.org/x/time/rate"
|
||||
)
|
||||
|
||||
const apiURL = "http://metasnap.debian.net/cgi-bin/api?"
|
||||
// Note: Metasnap does not have all the packages, and its API is
|
||||
// rather buggy.
|
||||
|
||||
var archives = []string{
|
||||
"debian",
|
||||
"debian-security",
|
||||
"debian-backports",
|
||||
// "debian-archive",
|
||||
// "debian-debug",
|
||||
// "debian-ports",
|
||||
// "debian-volatile",
|
||||
}
|
||||
const apiURL = "http://metasnap.debian.net/cgi-bin/api?"
|
||||
|
||||
var (
|
||||
limiterTimeout time.Duration = time.Second
|
||||
@ -100,22 +93,16 @@ type Snapshot struct {
|
||||
Last string
|
||||
}
|
||||
|
||||
type PackageInfo struct {
|
||||
type Repo struct {
|
||||
Archive string
|
||||
Suite string
|
||||
Component string
|
||||
Snapshot Snapshot
|
||||
}
|
||||
|
||||
func GetPackageInfo(pkg, arch, version string) (infos []PackageInfo, err error) {
|
||||
var result string
|
||||
|
||||
for _, archive := range archives {
|
||||
result, err = queryAPIf("archive=%s&pkg=%s&arch=%s&ver=%s",
|
||||
archive, pkg, arch, version)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
func GetRepo(archive, pkg, arch, ver string) (repos []Repo, err error) {
|
||||
result, err := queryAPIf("archive=%s&pkg=%s&arch=%s&ver=%s",
|
||||
archive, pkg, arch, ver)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
@ -137,7 +124,8 @@ func GetPackageInfo(pkg, arch, version string) (infos []PackageInfo, err error)
|
||||
return
|
||||
}
|
||||
|
||||
info := PackageInfo{
|
||||
repo := Repo{
|
||||
Archive: archive,
|
||||
Suite: fields[0],
|
||||
Component: fields[1],
|
||||
Snapshot: Snapshot{
|
||||
@ -146,10 +134,10 @@ func GetPackageInfo(pkg, arch, version string) (infos []PackageInfo, err error)
|
||||
},
|
||||
}
|
||||
|
||||
infos = append(infos, info)
|
||||
repos = append(repos, repo)
|
||||
}
|
||||
|
||||
if len(infos) == 0 {
|
||||
if len(repos) == 0 {
|
||||
err = ErrNotFound
|
||||
return
|
||||
}
|
||||
|
@ -6,9 +6,9 @@ import (
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
)
|
||||
|
||||
func TestGetPackageInfo(t *testing.T) {
|
||||
func TestGetRepo(t *testing.T) {
|
||||
// existing
|
||||
infos, err := GetPackageInfo("linux-image-3.8-trunk-amd64",
|
||||
infos, err := GetRepo("debian", "linux-image-3.8-trunk-amd64",
|
||||
"amd64", "3.8.2-1~experimental.1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -17,7 +17,7 @@ func TestGetPackageInfo(t *testing.T) {
|
||||
t.Log(spew.Sdump(infos))
|
||||
|
||||
// non-existing
|
||||
infos, err = GetPackageInfo("meh", "amd64", "meh")
|
||||
infos, err = GetRepo("debian", "meh", "amd64", "meh")
|
||||
if err == nil {
|
||||
t.Fatalf("should not be ok, result: %s", spew.Sdump(infos))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user