package main
import (
//"fmt"
"html/template"
"log"
"net/http"
"os"
//"regexp"
//"strings"
//"maps"
//"slices"
)
var templates *template.Template = template.New("")
func hdlr_renderHTML(in_leaderPath string, in_fileName string) http.HandlerFunc{
return func (resp http.ResponseWriter, req *http.Request){
err := templates.ExecuteTemplate(resp, in_fileName, nil) // resp, in_fileName, contextObj)
if(err != nil){
http.Error(resp, err.Error(), http.StatusInternalServerError)
}
}
}
func main(){
http.Handle("/", http.FileServer(http.Dir("./website/static")))
template_renders := map[string]string {
"/film/view/": "film/index.html",
"/film/edit/": "index.html",
"/list/view/": "index.html",
"/list/edit/": "index.html",
"/group/view/": "index.html",
"/group/edit/": "index.html",
}
for _,i_file := range template_renders{
text, err := os.ReadFile("./website/templates/" + i_file)
if(err != nil){
panic(err)
}
templates.New(i_file).Parse(string(text))
}
for i_path,i_file := range template_renders{
http.HandleFunc(i_path, hdlr_renderHTML(i_path, i_file))
}
//fmt.Println("Welcome to moira_db!");
log.Fatal(http.ListenAndServe(":8000", nil))
}