feat: #10 added the base for the class on the page

This commit is contained in:
2023-09-23 11:44:36 +01:00
parent 1964303dce
commit 04de6ad574
8 changed files with 273 additions and 13 deletions

View File

@@ -16,8 +16,22 @@ import (
dbtypes "git.andr3h3nriqu3s.com/andr3/fyp/logic/db_types"
)
func Mul (n1 int, n2 int) int {
return n1 * n2
}
func Add (n1 int, n2 int) int {
return n1 + n2
}
func baseLoadTemplate(base string, path string) (*template.Template, any) {
return template.New(base).ParseFiles(
funcs := map[string]any {
"startsWith": strings.HasPrefix,
"replace": strings.Replace,
"mul": Mul,
"add": Add,
}
return template.New(base).Funcs(funcs).ParseFiles(
"./views/"+base,
"./views/"+path,
"./views/partials/header.html",
@@ -82,7 +96,7 @@ func LoadHtml(writer http.ResponseWriter, path string, data interface{}) {
}
}
func LoadError(writer http.ResponseWriter, path string, base string, data AnyMap) {
func LoadDefineTemplate(writer http.ResponseWriter, path string, base string, data AnyMap) {
if data == nil {
data = map[string]interface{} {
"Error": true,
@@ -91,7 +105,14 @@ func LoadError(writer http.ResponseWriter, path string, base string, data AnyMap
data["Error"] = true
}
tmpl, err := template.New("").Parse("{{template \"" + base + "\" . }}")
funcs := map[string]any {
"startsWith": strings.HasPrefix,
"mul": Mul,
"replace": strings.Replace,
"add": Add,
}
tmpl, err := template.New("").Funcs(funcs).Parse("{{template \"" + base + "\" . }}")
if err != nil {
panic("Lol")
}