more functionality
This commit is contained in:
@@ -7,7 +7,27 @@ import (
|
||||
"golang.org/x/mod/modfile"
|
||||
)
|
||||
|
||||
func LoadAndComputePairs(filename string) ([]libyear.Pair, error) {
|
||||
type logger interface {
|
||||
Logf(f string, s ...interface{})
|
||||
Debugf(f string, s ...interface{})
|
||||
}
|
||||
|
||||
type GoMod struct {
|
||||
IncludeIndirect bool
|
||||
ProxyLoader Queryer
|
||||
Logger logger
|
||||
}
|
||||
|
||||
func isReplaced(module string, replaces []*modfile.Replace) bool {
|
||||
for i := range replaces {
|
||||
if module == replaces[i].Old.Path {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (g *GoMod) LoadAndComputePairs(filename string) ([]libyear.Pair, error) {
|
||||
b, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -16,14 +36,20 @@ func LoadAndComputePairs(filename string) ([]libyear.Pair, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
q := Queryer{}
|
||||
|
||||
pairs := []libyear.Pair{}
|
||||
|
||||
for v := range f.Require {
|
||||
if f.Require[v].Mod.Path != "" && f.Require[v].Mod.Version != "" {
|
||||
latest := q.GetLatestVersion(f.Require[v].Mod.Path)
|
||||
current := q.GetVersion(f.Require[v].Mod.Path, f.Require[v].Mod.Version)
|
||||
if isReplaced(f.Require[v].Mod.Path, f.Replace) {
|
||||
g.Logger.Logf("%s is replaced, skipping...\n", f.Require[v].Mod.Path)
|
||||
continue
|
||||
}
|
||||
if !g.IncludeIndirect && f.Require[v].Indirect {
|
||||
g.Logger.Logf("%s is indirect, skipping...\n", f.Require[v].Mod.Path)
|
||||
continue
|
||||
}
|
||||
latest := g.ProxyLoader.GetLatestVersion(f.Require[v].Mod.Path)
|
||||
current := g.ProxyLoader.GetVersion(f.Require[v].Mod.Path, f.Require[v].Mod.Version)
|
||||
pairs = append(pairs, libyear.Pair{
|
||||
Name: f.Require[v].Mod.Path,
|
||||
Current: current,
|
||||
|
@@ -4,7 +4,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
@@ -18,6 +17,7 @@ type Queryer struct {
|
||||
Root string
|
||||
Client http.Client
|
||||
Cache cache.Cache
|
||||
Logger logger
|
||||
}
|
||||
|
||||
type majorVersion struct {
|
||||
@@ -59,17 +59,17 @@ func (q *Queryer) findLatestMajorVersion(module string) string {
|
||||
}
|
||||
|
||||
func (q *Queryer) makeProxyRequest(mod string) libyear.Info {
|
||||
log.Printf("makeProxyRequest for https://proxy.golang.org/%s", mod)
|
||||
if q.Root == "" {
|
||||
q.Root = "https://proxy.golang.org/"
|
||||
}
|
||||
q.Logger.Debugf("makeProxyRequest for %s/%s\n", q.Root, mod)
|
||||
|
||||
u, _ := url.Parse(q.Root)
|
||||
u.Path = mod
|
||||
|
||||
i := q.Cache.Get(u.String())
|
||||
if i.Version != "" {
|
||||
log.Printf("cache hit for https://proxy.golang.org/%s", mod)
|
||||
q.Logger.Debugf("cache hit for https://proxy.golang.org/%s\n", mod)
|
||||
return i
|
||||
}
|
||||
req, err := http.NewRequest("GET", u.String(), nil)
|
||||
|
Reference in New Issue
Block a user