From 5c7bfc21ed6d70d96fd5f444e7b2e5a1523317da Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Mon, 11 Sep 2023 20:54:28 +0300 Subject: [PATCH] [WIP] settings up template and static files embedding --- go.mod | 3 +++ main.go | 11 +++++++++++ resources/resources.go | 7 +++++++ templates/download-result.html | 2 +- 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 go.mod create mode 100644 resources/resources.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..61ede30 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module gitea.hbanafa.com/hesham/viddl + +go 1.21.0 diff --git a/main.go b/main.go index 04a93c5..9874443 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "embed" "encoding/json" "fmt" "html/template" @@ -8,6 +9,8 @@ import ( "log" "net/http" "time" + + "gitea.hbanafa.com/hesham/viddl/resources" ) const ( @@ -77,6 +80,14 @@ func writeJSONResponse(w http.ResponseWriter, s string) http.ResponseWriter { } +var templates *template.Template + +func init() { + + log.Println("[ init ] Starting...") + templates = template.Must(template.ParseFS(resources.TemplatesFS, "templates/*.html")) + +} func main() { handler := http.NewServeMux() diff --git a/resources/resources.go b/resources/resources.go new file mode 100644 index 0000000..c072981 --- /dev/null +++ b/resources/resources.go @@ -0,0 +1,7 @@ +package resources + +import "embed" + +//go:embed gitea.hbanafa.com/hesham/viddl/resources +var TemplatesFS embed.FS + diff --git a/templates/download-result.html b/templates/download-result.html index 9fbcfc4..3a65d97 100644 --- a/templates/download-result.html +++ b/templates/download-result.html @@ -1 +1 @@ -Download +Download