---
name: crud_delete_handler
kind: function
lang: go
domain: infra
version: "1.0.0"
purity: impure
signature: "func CRUDDeleteHandler(res CRUDResource, db *sql.DB) http.HandlerFunc"
description: "Genera un handler HTTP DELETE /{id} que borra un registro. Si el recurso es SoftDelete, hace UPDATE deleted_at en vez de DELETE. Responde 204 sin body, 404 si no existe."
tags: [crud, delete, handler, http, sqlite, soft-delete, infra]
uses_functions: [http_error_response_go_infra]
uses_types: [CRUDResource_go_infra, HTTPError_go_infra]
returns: []
returns_optional: false
error_type: "error_go_core"
imports: [database/sql, fmt, net/http, time]
params:
  - name: res
    desc: "definicion del recurso (SoftDelete determina el modo de borrado)"
  - name: db
    desc: "conexion *sql.DB a SQLite"
output: "http.HandlerFunc que borra un registro"
tested: true
tests: ["hard delete fisico si soft_delete false", "soft delete via UPDATE deleted_at si soft_delete true", "retorna 404 si no existe", "retorna 204 sin body"]
test_file_path: "functions/infra/crud_test.go"
file_path: "functions/infra/crud_delete_handler.go"
---

## Ejemplo

```go
handler := CRUDDeleteHandler(res, db)
mux.Handle("DELETE /api/projects/{id}", handler)
// curl -X DELETE localhost:8080/api/projects/abc-123
```

## Notas

Impura. Responde 204 No Content sin body en exito (convencion REST). Si el recurso es SoftDelete, actualiza deleted_at y updated_at con el timestamp actual, preservando el registro para auditoria. Un segundo DELETE sobre un recurso soft-deleted responde 404 (se considera que ya fue borrado).
