79442720

Date: 2025-02-16 07:13:41
Score: 0.5
Natty:
Report link

Troubleshooting Steps:

  1. Check if the request hits the server → Add this to deleteUser:

    log.Println("DELETE request received for ID:", id)
    

    If nothing shows in logs, request isn't reaching the handler.

  2. Verify the id is valid → Convert to integer before querying:

    idInt, err := strconv.Atoi(id)
    if err != nil {
        log.Println("Invalid ID:", id)
        w.WriteHeader(http.StatusBadRequest)
        return
    }
    
  3. Check if the user exists → Run manually in Postgres:

    SELECT * FROM users WHERE id = 1;
    

    If no result, your DELETE won't work.

  4. Confirm the row is deleted → After Exec, check:

    rowsAffected, _ := result.RowsAffected()
    if rowsAffected == 0 {
        log.Println("No user deleted")
        w.WriteHeader(http.StatusNotFound)
        return
    }
    
  5. CORS Issue? → If using a browser, check DevTools (Network > XHR) and ensure DELETE isn't blocked.

Try these and check your logs. Let me know what you find! 🚀

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: Sad Ebadi