💄 Move DELETE logic to specific function

This commit is contained in:
Ada 2023-12-28 22:28:32 +01:00
parent 1731efcc28
commit 7ecb747b72
2 changed files with 3 additions and 6 deletions

2
db.go
View file

@ -43,7 +43,7 @@ func getContent(key string) string {
return db.HGet(ctx, key, "content").Val()
}
func deleteContent(key string) {
func DeleteContent(key string) {
err := db.Del(ctx, key)
if err != nil {
log.Println(err)

View file

@ -68,11 +68,8 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
case "DELETE":
if UrlExist(path) {
secret := r.URL.Query().Get("secret")
if secret == db.HGet(ctx, path, "secret").Val() {
err := db.Del(ctx, path)
if err != nil {
log.Println(err)
}
if VerifySecret(path, secret) {
DeleteContent(path)
w.WriteHeader(http.StatusNoContent)
} else {
w.WriteHeader(http.StatusForbidden)