Delete modules in case of breaking changes or invalid checksums, compatibility with go mod download (#10)

* add module invalidation via DELETE request
* add go mod download vcs provider
This commit is contained in:
Serge Zaitsev
2019-10-07 08:10:02 +02:00
committed by GitHub
parent 0868adad0a
commit 7a37ec05c4
7 changed files with 181 additions and 61 deletions

View File

@@ -158,6 +158,10 @@ func (api *api) ServeHTTP(w http.ResponseWriter, r *http.Request) {
version = m[2]
}
module = decodeBangs(module)
if r.Method == http.MethodDelete && version != "" {
api.delete(w, r, module, version)
return
}
httpRequests.Add(route.id, 1)
defer func() {
v := &expvar.Float{}
@@ -179,7 +183,7 @@ func (api *api) vcs(ctx context.Context, module string) vcs.VCS {
return path.vcs(module)
}
}
return vcs.NewGit(api.log, api.gitdir, module, vcs.NoAuth())
return vcs.NewGoMod(api.log, module)
}
func (api *api) module(ctx context.Context, module string, version vcs.Version) ([]byte, time.Time, error) {
@@ -232,7 +236,7 @@ func (api *api) list(w http.ResponseWriter, r *http.Request, module, version str
if err != nil {
api.log("api.list", "module", module, "error", err)
httpErrors.Add(module, 1)
http.Error(w, err.Error(), http.StatusInternalServerError)
http.Error(w, err.Error(), http.StatusNotFound)
return
}
@@ -248,7 +252,7 @@ func (api *api) info(w http.ResponseWriter, r *http.Request, module, version str
if err != nil {
api.log("api.info", "module", module, "version", version, "error", err)
httpErrors.Add(module, 1)
http.Error(w, err.Error(), http.StatusInternalServerError)
http.Error(w, err.Error(), http.StatusNotFound)
return
}
@@ -283,8 +287,17 @@ func (api *api) zip(w http.ResponseWriter, r *http.Request, module, version stri
if err != nil {
api.log("api.zip", "module", module, "version", version, "error", err)
httpErrors.Add(module, 1)
http.Error(w, err.Error(), http.StatusInternalServerError)
http.Error(w, err.Error(), http.StatusNotFound)
return
}
io.Copy(w, bytes.NewReader(b))
}
func (api *api) delete(w http.ResponseWriter, r *http.Request, module, version string) {
for _, store := range api.stores {
if err := store.Del(r.Context(), module, vcs.Version(version)); err != nil {
http.Error(w, err.Error(), http.StatusNotFound)
return
}
}
}