From 2231c15975634a730d213c51ec532177c0ddcf71 Mon Sep 17 00:00:00 2001 From: navanchauhan Date: Mon, 17 Oct 2022 23:22:32 -0600 Subject: embed static folder --- main.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'main.go') diff --git a/main.go b/main.go index d2e6600..11a96a7 100644 --- a/main.go +++ b/main.go @@ -1,8 +1,10 @@ package main import ( + "embed" "fmt" "html/template" + "io/fs" "math" "net/http" "os" @@ -16,6 +18,9 @@ var globalVariables = GlobalVars{ Name: "510K Search", } +//go:embed static/* +var static embed.FS + func create_pdf_url(year string, knumber string) string { year_int, _ := strconv.Atoi(year[0:2]) if year[0] == '0' || year[0] == '1' || year[0] == '2' || year[0] == '3' || year[0] == '4' || year[0] == '5' && year[0:2] != "01" && year[0:2] != "00" { @@ -45,6 +50,8 @@ func main() { Host: meili_host, }) + contentStatic, _ := fs.Sub(static, "static") + funcMap := template.FuncMap{ "unescapeHTML": func(s string) template.HTML { return template.HTML(s) @@ -62,6 +69,8 @@ func main() { index := client.Index("510k") + http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.FS(contentStatic)))) + http.HandleFunc("/classic/", func(w http.ResponseWriter, r *http.Request) { classicIndexTemplate.Execute(w, BaseResponse{ GlobalVars: globalVariables, -- cgit v1.2.3