initial commit

This commit is contained in:
Adrian Zürcher
2025-08-04 16:59:29 +02:00
commit 21b41de886
10 changed files with 470 additions and 0 deletions

40
handlers/killHandler.go Normal file
View File

@@ -0,0 +1,40 @@
package handlers
import (
"html/template"
"net/http"
"os"
"processSupervisor/models"
"strconv"
)
func KillHandler(w http.ResponseWriter, r *http.Request) {
pidStr := r.URL.Query().Get("pid")
pid, err := strconv.Atoi(pidStr)
if err != nil {
http.Error(w, "Invalid PID", http.StatusBadRequest)
return
}
proc, err := os.FindProcess(pid)
if err != nil {
http.Error(w, "Process not found", http.StatusNotFound)
return
}
err = proc.Kill()
if err != nil {
http.Error(w, "Failed to kill process", http.StatusInternalServerError)
return
}
// Return updated table partial (same as HTMX request)
processes, err := models.GetProcesses()
if err != nil {
http.Error(w, "Failed to get processes", http.StatusInternalServerError)
return
}
tmpl := template.Must(template.ParseFiles("templates/partials/table.html"))
tmpl.Execute(w, processes)
}