Files
tecamino-proccessSupervisor/main.go
2025-08-05 18:45:19 +02:00

44 lines
1.1 KiB
Go

package main
import (
"embed"
"flag"
"fmt"
"log"
"net/http"
"processSupervisor/handlers"
)
//go:embed templates/*.html templates/*/*.html
var templatesFS embed.FS
//go:embed static
var staticFS embed.FS
func main() {
port := flag.Uint("port", 9400, "listening port")
htop, err := handlers.NewHTopHandler(&templatesFS)
if err != nil {
panic(err)
}
mainPage, err := handlers.NewMainPage(&templatesFS)
if err != nil {
panic(err)
}
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.FS(staticFS))))
http.HandleFunc("/taskmanager/htop", htop.UpdateHTop)
http.HandleFunc("/", mainPage.UpdateMainPage)
http.HandleFunc("/start-process", mainPage.StartProcess)
http.HandleFunc("/stop-process", mainPage.StopProcess)
http.HandleFunc("/restart-process", mainPage.RestartProcess)
http.HandleFunc("/taskmanager/kill", handlers.KillHandler)
http.HandleFunc("/taskmanager/usage", handlers.UsageHandler)
log.Printf("Listening on http://localhost:%d\n", *port)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), nil))
}