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