From d801eee16f37d8b5441391f51fd2f3d24d65de5b Mon Sep 17 00:00:00 2001 From: kun Date: Fri, 5 Jul 2019 15:52:41 +0800 Subject: [PATCH] fix cache issue --- pkg/proxy/proxy.go | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/pkg/proxy/proxy.go b/pkg/proxy/proxy.go index 53fa84a..ad03103 100644 --- a/pkg/proxy/proxy.go +++ b/pkg/proxy/proxy.go @@ -107,19 +107,30 @@ func NewProxy(cache string) http.Handler { } switch suf { case "/@v/list": - if info, err := repo.Versions(""); err != nil { - ReturnInternalServerError(w, err) - } else { - data := strings.Join(info, "\n") - ReturnSuccess(w, []byte(data)) - } - case "/@latest": - modLatestInfo, err := repo.Latest() - if err != nil { + modPath := strings.Trim(strings.TrimSuffix(r.URL.Path, "/@v/list"), "/") + modPath, err := module.DecodePath(modPath) + if err != nil { ReturnInternalServerError(w, err) return } - ReturnJsonData(w, modLatestInfo) + + modload.LoadBuildList() + mods := modload.ListModules([]string{modPath + "@latest"}, false, true) + + data := []byte(strings.Join(mods[0].Versions, "\n") + "\n") + if len(data) == 1 { + data = nil + } + w.Write(data) + return + case "/@latest": + rev, err := repo.Stat("latest") + if err != nil { + errLogger.Printf("latest failed: %v", err) + return + } + ReturnJsonData(w, rev) + return } return }