Routing, templating, and database handling

This commit is contained in:
max
2022-10-20 11:59:33 -05:00
parent 38352de02f
commit e73c006550
10 changed files with 204 additions and 0 deletions

View File

@ -0,0 +1,20 @@
package templating
import (
"GoWeb/app"
"html/template"
"log"
"net/http"
)
func RenderTemplate(app *app.App, w http.ResponseWriter, contentPath string, data any) {
templatePath := app.Config.Template.BaseName
t, _ := template.ParseFiles(templatePath, contentPath)
err := t.Execute(w, data)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), 500)
return
}
}