Add auth, rest api, svelte frontend, build structure
This commit is contained in:
33
internal/handlers/admin.go
Normal file
33
internal/handlers/admin.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
"git.clustercockpit.org/moebiusband/go-http-skeleton/web"
|
||||
"github.com/olivere/vite"
|
||||
)
|
||||
|
||||
func AdminHandler() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
tpl := template.Must(template.ParseFS(web.Templates, "templates/admin.html", "templates/base.html"))
|
||||
viteFragment, err := vite.HTMLFragment(vite.Config{
|
||||
FS: web.StaticAssets,
|
||||
IsDev: false,
|
||||
})
|
||||
if err != nil {
|
||||
http.Error(w, "Error instantiating vite fragment", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
data := web.PageData{
|
||||
Title: "Admin",
|
||||
Vite: viteFragment,
|
||||
}
|
||||
if err := tpl.ExecuteTemplate(w, "base", data); err != nil {
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
slog.Error("Error executing template", "error", err)
|
||||
}
|
||||
}
|
||||
}
|
@@ -8,29 +8,12 @@ import (
|
||||
"git.clustercockpit.org/moebiusband/go-http-skeleton/web"
|
||||
)
|
||||
|
||||
type PageData struct {
|
||||
Title string
|
||||
}
|
||||
|
||||
func RootHandler() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
slog.Info("Render root handler")
|
||||
tpl := template.Must(template.ParseFS(web.Templates, "templates/index.html", "templates/base.html"))
|
||||
|
||||
// basefile, err := web.Templates.ReadFile("templates/base.html")
|
||||
// if err != nil {
|
||||
// http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
// slog.Error("Error reading template", "error", err)
|
||||
// return
|
||||
// }
|
||||
// file, err := web.Templates.ReadFile("templates/index.html")
|
||||
// if err != nil {
|
||||
// http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
// slog.Error("Error reading template", "error", err)
|
||||
// return
|
||||
// }
|
||||
|
||||
data := PageData{
|
||||
data := web.PageData{
|
||||
Title: "DyeForYarn",
|
||||
}
|
||||
if err := tpl.ExecuteTemplate(w, "base", data); err != nil {
|
||||
|
Reference in New Issue
Block a user