48 lines
1.8 KiB
Go
48 lines
1.8 KiB
Go
package templates
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"text/template"
|
|
)
|
|
|
|
type InputProps struct {
|
|
Type string
|
|
Name string
|
|
Required bool
|
|
Value string
|
|
Error string
|
|
MinLength uint
|
|
}
|
|
|
|
var tmpls map[string]*template.Template = loadTemplates()
|
|
|
|
func Execute(w http.ResponseWriter, name string, data any) {
|
|
err := tmpls[name].Execute(w, data)
|
|
if err != nil {
|
|
log.Printf("Failed to execute '%s' template: %s\n", name, err)
|
|
return
|
|
}
|
|
}
|
|
|
|
func loadTemplates() map[string]*template.Template {
|
|
homeTmpl := template.Must(template.ParseFiles("templates/base.gotmpl", "templates/home.gotmpl"))
|
|
loginTmpl := template.Must(template.ParseFiles("templates/base.gotmpl", "templates/login.gotmpl"))
|
|
registerTmpl := template.Must(template.ParseFiles("templates/base.gotmpl", "templates/register.gotmpl"))
|
|
foreignTmpl := template.Must(template.ParseFiles("templates/base.gotmpl", "templates/foreign_wishlist.gotmpl"))
|
|
publicWishlistTmpl := template.Must(template.ParseFiles("templates/base.gotmpl", "templates/public_foreign_wishlist.gotmpl"))
|
|
errorTmpl := template.Must(template.ParseFiles("templates/base.gotmpl", "templates/error_page.gotmpl"))
|
|
groupTmpl := template.Must(template.ParseFiles("templates/base.gotmpl", "templates/group_page.gotmpl"))
|
|
publicGroupTmpl := template.Must(template.ParseFiles("templates/base.gotmpl", "templates/public_group_page.gotmpl"))
|
|
return map[string]*template.Template{
|
|
"home.gotmpl": homeTmpl,
|
|
"login.gotmpl": loginTmpl,
|
|
"register.gotmpl": registerTmpl,
|
|
"foreign_wishlist.gotmpl": foreignTmpl,
|
|
"public_foreign_wishlist.gotmpl": publicWishlistTmpl,
|
|
"error_page.gotmpl": errorTmpl,
|
|
"group_page.gotmpl": groupTmpl,
|
|
"public_group_page.gotmpl": publicGroupTmpl,
|
|
}
|
|
}
|