From 3a957471bc49d57fa979fa2314bac1997c0fed2f 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 | 10 ++++------ main.go | 7 ++----- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/db.go b/db.go index a156541..aaaa0ad 100644 --- a/db.go +++ b/db.go @@ -2,9 +2,10 @@ package main import ( "context" - "github.com/redis/go-redis/v9" "log" "time" + + "github.com/redis/go-redis/v9" ) var ctx = context.Background() @@ -43,9 +44,6 @@ func getContent(key string) string { return db.HGet(ctx, key, "content").Val() } -func deleteContent(key string) { - err := db.Del(ctx, key) - if err != nil { - log.Println(err) - } +func DeleteContent(key string) { + db.Del(ctx, key) } diff --git a/main.go b/main.go index 3064b46..d75aa4b 100644 --- a/main.go +++ b/main.go @@ -80,11 +80,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)