clustvirt/main.go
Matthew Stobbs 2419d5d3a6 add basic chi http server
- added air to reload the server on changes automatically
- added tailwindcss
- added base page structure in html using _index, _header and _footer
- added static homepage
- added style.css built by tailwindcss
- added basic View object to control views and templates
2024-03-13 19:12:48 -06:00

65 lines
1.6 KiB
Go

package main
import (
"log"
"net/http"
"git.staur.ca/stobbsm/clustvirt/view"
"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
fs := http.StripPrefix("/static/", http.FileServer(http.Dir("public")))
r := chi.NewRouter()
r.Use(middleware.Logger)
r.Get("/", 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")
}
log.Println(w.Write([]byte("Nothing on / yet")))
})
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("/home", 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")
}
w.Header().Add("Content", "text/html")
log.Println(view.ViewHome.Render(w, nil))
})
log.Println(http.ListenAndServe(":3000", r))
}