2024-03-10 07:15:49 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2024-03-14 01:12:48 +00:00
|
|
|
"net/http"
|
2024-03-12 01:39:17 +00:00
|
|
|
|
2024-03-16 04:50:24 +00:00
|
|
|
"git.staur.ca/stobbsm/clustvirt/view/components"
|
|
|
|
"git.staur.ca/stobbsm/clustvirt/view/layouts"
|
2024-03-15 17:55:28 +00:00
|
|
|
"git.staur.ca/stobbsm/clustvirt/view/static"
|
2024-03-16 04:50:24 +00:00
|
|
|
"github.com/a-h/templ"
|
2024-03-14 01:12:48 +00:00
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
"github.com/go-chi/chi/v5/middleware"
|
2024-03-10 07:15:49 +00:00
|
|
|
)
|
|
|
|
|
2024-03-14 01:12:48 +00:00
|
|
|
const DEBUG bool = true
|
|
|
|
|
2024-03-10 07:15:49 +00:00
|
|
|
func main() {
|
|
|
|
log.Println("Starting clustvirt, the libvirt cluster manager")
|
|
|
|
|
2024-03-14 01:12:48 +00:00
|
|
|
//venus, err := host.ConnectHost(host.URI_QEMU_SSH_SYSTEM, "venus.staur.ca")
|
|
|
|
//if err != nil {
|
|
|
|
// log.Fatal(err)
|
|
|
|
//}
|
|
|
|
//defer venus.Close()
|
|
|
|
//lm, err := venus.GetGuestByName("logan-minecraft")
|
|
|
|
//if err != nil {
|
|
|
|
// log.Fatal(err)
|
|
|
|
//}
|
|
|
|
//defer lm.Close()
|
|
|
|
|
|
|
|
// Start webserver and serve homepage
|
|
|
|
|
2024-03-16 04:50:24 +00:00
|
|
|
defaultNavBar := []components.NavItem{
|
|
|
|
{Name: "Home", Href: "/"},
|
|
|
|
{Name: "About", Href: "/about"},
|
|
|
|
}
|
2024-03-14 01:12:48 +00:00
|
|
|
fs := http.StripPrefix("/static/", http.FileServer(http.Dir("public")))
|
|
|
|
|
|
|
|
r := chi.NewRouter()
|
|
|
|
r.Use(middleware.Logger)
|
|
|
|
r.Get("/static/*", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
defer r.Body.Close()
|
|
|
|
if DEBUG {
|
|
|
|
w.Header().Add("Cache-Control", "no-cache, no-store, must-revalidate")
|
|
|
|
w.Header().Add("Pragma", "no-cache")
|
|
|
|
w.Header().Add("Expire", "0")
|
|
|
|
}
|
|
|
|
fs.ServeHTTP(w, r)
|
|
|
|
})
|
2024-03-16 04:50:24 +00:00
|
|
|
r.Get("/", templ.Handler(layouts.Manager("Cluster Manager", "ClustVirt", defaultNavBar)).ServeHTTP)
|
|
|
|
r.Get("/about", templ.Handler(static.Home()).ServeHTTP)
|
2024-03-14 01:12:48 +00:00
|
|
|
|
|
|
|
log.Println(http.ListenAndServe(":3000", r))
|
2024-03-10 07:15:49 +00:00
|
|
|
}
|