From 2003c8064e7e8209d765eaac4003c47a122c057f Mon Sep 17 00:00:00 2001 From: navanchauhan Date: Mon, 17 Oct 2022 23:58:36 -0600 Subject: embed templates --- main.go | 11 ++++++----- templates/mytemplates.go | 8 ++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 templates/mytemplates.go 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 -- cgit v1.2.3