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
11
main.go
11
main.go
|
@ -64,12 +64,10 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
|
|||
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||
}
|
||||
case "DELETE":
|
||||
if strings.HasPrefix(path, "/delete") {
|
||||
urlItem := strings.Split(path, "/")
|
||||
if urlExist("/" + urlItem[2]) {
|
||||
if urlExist(path) {
|
||||
secret := r.URL.Query().Get("secret")
|
||||
if secret == db.HGet(ctx, "/"+urlItem[2], "secret").Val() {
|
||||
err := db.Del(ctx, "/"+urlItem[2])
|
||||
if secret == db.HGet(ctx, path, "secret").Val() {
|
||||
err := db.Del(ctx, path)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
@ -80,9 +78,6 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
|
|||
} else {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
} else {
|
||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue