Matthew Stobbs
223496075a
- Starting on main manager page - Manager layout will be included in the manager page - Manager page will use htmx to load different components via api
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
|
|
"git.staur.ca/stobbsm/clustvirt/view/components"
|
|
"git.staur.ca/stobbsm/clustvirt/view/layouts"
|
|
"git.staur.ca/stobbsm/clustvirt/view/static"
|
|
"github.com/a-h/templ"
|
|
"github.com/go-chi/chi/v5"
|
|
"github.com/go-chi/chi/v5/middleware"
|
|
)
|
|
|
|
const DEBUG bool = true
|
|
|
|
func main() {
|
|
log.Println("Starting clustvirt, the libvirt cluster manager")
|
|
|
|
//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
|
|
|
|
defaultNavBar := []components.NavItem{
|
|
{Name: "Home", Href: "/"},
|
|
{Name: "About", Href: "/about"},
|
|
}
|
|
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)
|
|
})
|
|
r.Get("/", templ.Handler(layouts.Manager("Cluster Manager", "ClustVirt", defaultNavBar)).ServeHTTP)
|
|
r.Get("/about", templ.Handler(static.Home()).ServeHTTP)
|
|
|
|
log.Println(http.ListenAndServe(":3000", r))
|
|
}
|