WIP: ♻️ Restructure test #36
2 changed files with 6 additions and 11 deletions
10
db.go
10
db.go
|
@ -2,9 +2,10 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/redis/go-redis/v9"
|
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/redis/go-redis/v9"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ctx = context.Background()
|
var ctx = context.Background()
|
||||||
|
@ -43,9 +44,6 @@ func getContent(key string) string {
|
||||||
return db.HGet(ctx, key, "content").Val()
|
return db.HGet(ctx, key, "content").Val()
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteContent(key string) {
|
func DeleteContent(key string) {
|
||||||
err := db.Del(ctx, key)
|
db.Del(ctx, key)
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
7
main.go
7
main.go
|
@ -80,11 +80,8 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
|
||||||
case "DELETE":
|
case "DELETE":
|
||||||
if UrlExist(path) {
|
if UrlExist(path) {
|
||||||
secret := r.URL.Query().Get("secret")
|
secret := r.URL.Query().Get("secret")
|
||||||
if secret == db.HGet(ctx, path, "secret").Val() {
|
if VerifySecret(path, secret) {
|
||||||
err := db.Del(ctx, path)
|
DeleteContent(path)
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
}
|
|
||||||
w.WriteHeader(http.StatusNoContent)
|
w.WriteHeader(http.StatusNoContent)
|
||||||
} else {
|
} else {
|
||||||
w.WriteHeader(http.StatusForbidden)
|
w.WriteHeader(http.StatusForbidden)
|
||||||
|
|
Loading…
Reference in a new issue