From 7ecb747b725eb845b4b239ad80ddc5f9af3d3193 Mon Sep 17 00:00:00 2001 From: Ada Date: Thu, 28 Dec 2023 22:28:32 +0100 Subject: [PATCH] :lipstick: Move DELETE logic to specific function --- db.go | 2 +- main.go | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/db.go b/db.go index d6b60b7..89757c1 100644 --- a/db.go +++ b/db.go @@ -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) diff --git a/main.go b/main.go index 2fdec8a..266b00b 100644 --- a/main.go +++ b/main.go @@ -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)