package main import ( "embed" "flag" "fmt" "io/fs" "log" "net/http" "processSupervisor/htop" "processSupervisor/mainPage" ) //go:embed static var staticFS embed.FS func main() { port := flag.Uint("port", 9400, "listening port") cfgDir := flag.String("cfg", "./dist", "configuration directory") htopHandler, err := htop.NewHTopHandler() if err != nil { panic(err) } mP, err := mainPage.NewMainPage(*cfgDir) if err != nil { panic(err) } staticSub, err := fs.Sub(staticFS, "static") if err != nil { log.Fatal(err) } http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.FS(staticSub)))) http.HandleFunc("/taskmanager/htop", htopHandler.UpdateHTop) http.HandleFunc("/", mP.LoadMainPage) http.HandleFunc("/start-process", mP.StartProcess) http.HandleFunc("/stop-process", mP.StopProcess) http.HandleFunc("/restart-process", mP.RestartProcess) http.HandleFunc("/processes", mP.UpdateMainPage) http.HandleFunc("/taskmanager/kill", htop.KillHandler) http.HandleFunc("/taskmanager/usage", htop.UsageHandler) log.Printf("Listening on http://localhost:%d\n", *port) log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), nil)) }