add module invalidation via DELETE request

This commit is contained in:
Serge Zaitsev
2019-10-01 08:51:44 +02:00
parent 0868adad0a
commit f906c8009a
6 changed files with 90 additions and 57 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{}
@@ -288,3 +292,12 @@ func (api *api) zip(w http.ResponseWriter, r *http.Request, module, version stri
}
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.StatusInternalServerError)
return
}
}
}