You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

52 lines
858 B

package Webserver
import (
"html/template"
"net/http"
"path"
"PersonalWebsite/Helper"
)
type Unauthenticated struct {
FlashMsg string
}
var (
partials = []string{
"html/header.gohtml",
"html/sidebar.gohtml",
}
)
func ServeTemplate(w http.ResponseWriter, r *http.Request, mainFile string, v map[string]interface{}) {
var (
tpl *template.Template
files []string
e error
)
v["test"] = "Yeet"
files = []string{webRootJoin(mainFile)}
for _, p := range partials {
files = append(files, webRootJoin(p))
}
tpl, e = template.New(path.Base(files[0])).Funcs(
template.FuncMap{
"FormatTimestamp": Helper.FormatTimestamp,
},
).ParseFiles(files...)
if e != nil {
// TODO: Handle this
panic(e)
}
w.Header().Set("Content-type", "text/html")
e = tpl.Execute(w, v)
if e != nil {
// TODO: Handle this
panic(e)
}
}