Added Save/Load to db

Fixes #3. Fixes #2
This commit is contained in:
sm
2016-02-14 22:20:10 -08:00
parent af4faf0206
commit 4cfaf2124f
4 changed files with 70 additions and 17 deletions
+11 -1
View File
@@ -35,7 +35,17 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
http.Error(w, fmt.Sprintf("invalid path; prefix already taken %q", req.URL.Path), http.StatusConflict)
return
}
s.storage.Add(p)
if err := s.storage.Add(p); err != nil {
http.Error(w, fmt.Sprintf("unable to add package: %v", err), http.StatusInternalServerError)
return
}
if err := s.storage.Save(); err != nil {
http.Error(w, fmt.Sprintf("unable to store db: %v", err), http.StatusInternalServerError)
if err := s.storage.Remove(p.Path); err != nil {
fmt.Fprintf(w, "to add insult to injury, could not delete package: %v\n", err)
}
return
}
default:
http.Error(w, fmt.Sprintf("unsupported method %q; accepted: POST, GET", req.Method), http.StatusMethodNotAllowed)
}