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