summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornavanchauhan <navanchauhan@gmail.com>2022-10-17 23:58:36 -0600
committernavanchauhan <navanchauhan@gmail.com>2022-10-17 23:58:36 -0600
commit2003c8064e7e8209d765eaac4003c47a122c057f (patch)
tree8564ec4c706f9870708737b3efbd4de127756eea
parent01076278493fd722fc658e7d51b49267c9c37dff (diff)
embed templates
-rw-r--r--main.go11
-rw-r--r--templates/mytemplates.go8
2 files changed, 14 insertions, 5 deletions
diff --git a/main.go b/main.go
index 11a96a7..2ac4046 100644
--- a/main.go
+++ b/main.go
@@ -12,6 +12,7 @@ import (
"github.com/joho/godotenv"
"github.com/meilisearch/meilisearch-go"
+ mytemplates "github.com/navanchauhan/dogeknows-go/templates"
)
var globalVariables = GlobalVars{
@@ -59,13 +60,13 @@ func main() {
}
// Classic UI Templates
- classicIndexTemplate := template.Must(template.ParseFiles("templates/search.gtpl"))
- searchResTemplate := template.Must(template.New("results.gtpl").Funcs(funcMap).ParseFiles("templates/results.gtpl"))
+ classicIndexTemplate := template.Must(template.ParseFS(mytemplates.Templates, "search.gtpl"))
+ searchResTemplate := template.Must(template.New("results.gtpl").Funcs(funcMap).ParseFS(mytemplates.Templates, "results.gtpl"))
// v2.0 UI Templates
- indexTemplate := template.Must(template.ParseFiles("templates/home.html", "templates/components/section.html", "templates/components/header.html"))
- searchResultsTemplate2 := template.Must(template.New("search_results.html").Funcs(funcMap).ParseFiles("templates/search_results.html", "templates/components/section.html", "templates/components/header.html"))
- documentDetailsTemplate2 := template.Must(template.New("document_details.html").Funcs(funcMap).ParseFiles("templates/document_details.html", "templates/components/section.html", "templates/components/header.html"))
+ indexTemplate := template.Must(template.ParseFS(mytemplates.Templates, "home.html", "components/section.html", "components/header.html"))
+ searchResultsTemplate2 := template.Must(template.New("search_results.html").Funcs(funcMap).ParseFS(mytemplates.Templates, "search_results.html", "components/section.html", "components/header.html"))
+ documentDetailsTemplate2 := template.Must(template.New("document_details.html").Funcs(funcMap).ParseFS(mytemplates.Templates, "document_details.html", "components/section.html", "components/header.html"))
index := client.Index("510k")
diff --git a/templates/mytemplates.go b/templates/mytemplates.go
new file mode 100644
index 0000000..82dc999
--- /dev/null
+++ b/templates/mytemplates.go
@@ -0,0 +1,8 @@
+package mytemplates
+
+import "embed"
+
+// myTemplates represent the templates used by the application.
+//
+//go:embed *.html *.gtpl components/*.html
+var Templates embed.FS