refactor(backend): remove /delete for DELETE request
This commit is contained in:
parent
5e8f82c329
commit
edc278f585
1 changed files with 9 additions and 14 deletions
23
main.go
23
main.go
|
@ -64,24 +64,19 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||||
}
|
}
|
||||||
case "DELETE":
|
case "DELETE":
|
||||||
if strings.HasPrefix(path, "/delete") {
|
if urlExist(path) {
|
||||||
urlItem := strings.Split(path, "/")
|
secret := r.URL.Query().Get("secret")
|
||||||
if urlExist("/" + urlItem[2]) {
|
if secret == db.HGet(ctx, path, "secret").Val() {
|
||||||
secret := r.URL.Query().Get("secret")
|
err := db.Del(ctx, path)
|
||||||
if secret == db.HGet(ctx, "/"+urlItem[2], "secret").Val() {
|
if err != nil {
|
||||||
err := db.Del(ctx, "/"+urlItem[2])
|
log.Println(err)
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
}
|
|
||||||
w.WriteHeader(http.StatusNoContent)
|
|
||||||
} else {
|
|
||||||
w.WriteHeader(http.StatusForbidden)
|
|
||||||
}
|
}
|
||||||
|
w.WriteHeader(http.StatusNoContent)
|
||||||
} else {
|
} else {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusForbidden)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue