initial commit

This commit is contained in:
Daniel Hjartland
2024-11-26 18:08:49 +01:00
commit 75be79c6cf
26 changed files with 1885 additions and 0 deletions

19
reset.go Normal file
View File

@@ -0,0 +1,19 @@
package main
import "net/http"
func (cfg *apiConfig) handlerReset(w http.ResponseWriter, r *http.Request) {
if cfg.platform != "dev" {
w.WriteHeader(http.StatusForbidden)
w.Write([]byte("Reset is only allowed in dev environment."))
return
}
err := cfg.db.Reset()
if err != nil {
respondWithError(w, http.StatusInternalServerError, "Couldn't reset database", err)
return
}
w.WriteHeader(http.StatusOK)
w.Write([]byte("Database reset to initial state"))
}