From 63a40d39067482c70100eabacffe0492225e1fc6 Mon Sep 17 00:00:00 2001 From: PrivateGER Date: Tue, 19 Oct 2021 09:00:38 +0200 Subject: [PATCH] Add static resoure handler + directory --- .gitattributes | 2 ++ PageHandlers/Static.go | 13 +++++++++++++ main.go | 4 ++++ 3 files changed, 19 insertions(+) create mode 100644 .gitattributes create mode 100644 PageHandlers/Static.go diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..e36f8a3 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +*.min.js -text -diff -delta +*.min.css -text -diff -delta \ No newline at end of file diff --git a/PageHandlers/Static.go b/PageHandlers/Static.go new file mode 100644 index 0000000..40174f7 --- /dev/null +++ b/PageHandlers/Static.go @@ -0,0 +1,13 @@ +package PageHandlers + +import ( + "embed" + "net/http" +) + +//go:embed static +var staticEmbedFS embed.FS + +func Static(writer http.ResponseWriter, request *http.Request) { + http.FileServer(http.FS(staticEmbedFS)) +} diff --git a/main.go b/main.go index 353e1ce..56cc239 100644 --- a/main.go +++ b/main.go @@ -64,6 +64,10 @@ func main() { fmt.Println(time.Now().String(),request.URL) PageHandlers.View(writer, request, &FL, path) }) + http.HandleFunc("/static", func(writer http.ResponseWriter, request *http.Request) { + fmt.Println(time.Now().String(),request.URL) + PageHandlers.Static(writer, request) + }) http.Handle("/videos/", http.StripPrefix("/videos/", http.FileServer(http.Dir(path)))) err := http.ListenAndServe(":" + strconv.Itoa(port), nil)