From 7a8f54a192640c1a55db23f11ed8d8ca29cd1c22 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 27 Dec 2024 20:43:23 -0600 Subject: [PATCH] compute the timestamps each time --- indexHtml.go | 15 ++++----------- main.go | 22 +++------------------- repomap.go | 5 +---- 3 files changed, 8 insertions(+), 34 deletions(-) diff --git a/indexHtml.go b/indexHtml.go index f0c0fd3..71108ee 100644 --- a/indexHtml.go +++ b/indexHtml.go @@ -99,19 +99,12 @@ func indexBodyRepo(w http.ResponseWriter, gourl string, giturl string, desc stri // fmt.Fprintln(w, " "+gourl+"") fmt.Fprintln(w, " "+gourl+"") fmt.Fprintln(w, " \"pkg.go.dev\" ") - // for i, s := range versionMap { - // log.Println("found i =", i, "with", "s =", s) - // } var vtime, version string gourl = strings.TrimSpace(gourl) - if tmp, ok := versionMap[gourl]; ok { - // log.Info("gopath", gopath, "tmp", tmp) - parts := strings.Fields(tmp) - if len(parts) == 2 { - // log.Info("GOT HERE gopath", gopath, "tmp", tmp) - version = parts[0] - vtime = parts[1] - } + if repo, ok := gitMap[gourl]; ok { + version = repo.GetLastTag() + age := repo.NewestAge() + vtime = formatDuration(age) } log.Info("gopath", gourl, "dur", vtime, "version", version) diff --git a/main.go b/main.go index 6c3792b..df3b3ef 100644 --- a/main.go +++ b/main.go @@ -4,10 +4,10 @@ import ( "embed" "fmt" "net/http" - "strings" "time" "go.wit.com/lib/protobuf/forgepb" + "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) @@ -21,7 +21,7 @@ var resources embed.FS // var accessf, clientf *os.File var repoMap map[string]string -var versionMap map[string]string +var gitMap map[string]*gitpb.Repo var configfile []string var keysSorted []string var forge *forgepb.Forge @@ -40,7 +40,7 @@ func main() { } forge = forgepb.Init() - versionMap = make(map[string]string) + gitMap = make(map[string]*gitpb.Repo) repoMap = make(map[string]string) /* @@ -56,22 +56,6 @@ func main() { readRepomap() // readVersionFile() - var vtime string - var version string - for gopath, thing := range versionMap { - if tmp, ok := versionMap[gopath]; ok { - // log.Info("gopath", gopath, "tmp", tmp) - parts := strings.Fields(tmp) - if len(parts) == 2 { - // log.Info("GOT HERE gopath", gopath, "tmp", tmp) - version = parts[0] - vtime = parts[1] - } - } - log.Info("gopath", gopath, "info", thing, "dur", vtime, "version", version) - } - - log.Println("found log =", versionMap["go.wit.com/log"]) http.HandleFunc("/", okHandler) // go https() // use caddy instead p := fmt.Sprintf(":%d", argv.Port) diff --git a/repomap.go b/repomap.go index 31a1fd3..cf53d10 100644 --- a/repomap.go +++ b/repomap.go @@ -67,10 +67,7 @@ func readRepomap() { repo := forge.FindByGoPath(gopath) if repo != nil { - version := repo.GetLastTag() - age := repo.NewestAge() - log.Info("repo =", gopath, "real url =", repoMap[gopath], version, formatDuration(age)) - versionMap[gopath] = version + " " + formatDuration(age) + gitMap[gopath] = repo } else { log.Info("repo =", gopath, "real url =", repoMap[gopath], "not found") }