From e1fcf859104f5aaf7205c686ce996211eecc4b3b Mon Sep 17 00:00:00 2001 From: BroodjeAap Date: Mon, 29 Jun 2020 19:19:24 +0000 Subject: [PATCH] added static files and moved templates to own dir --- main.go | 8 ++++++-- static/js/stream.js | 1 + index.html => templates/index.html | 0 stream.html => templates/stream.html | 2 +- tmp/air_errors.log | 1 + 5 files changed, 9 insertions(+), 3 deletions(-) create mode 100755 static/js/stream.js rename index.html => templates/index.html (100%) rename stream.html => templates/stream.html (84%) create mode 100644 tmp/air_errors.log diff --git a/main.go b/main.go index bc3a4e1..178b21f 100755 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "log" "net/http" + "path/filepath" "text/template" ) @@ -12,7 +13,7 @@ type StreamURL struct { } func index(w http.ResponseWriter, r *http.Request) { - indexTemplate, err := template.ParseFiles(("index.html")) + indexTemplate, err := template.ParseFiles(filepath.Join("templates", "index.html")) if err != nil { log.Fatal(err) } @@ -27,7 +28,7 @@ func stream(w http.ResponseWriter, r *http.Request) { streamURL := StreamURL{ URL: r.FormValue("URL"), } - streamTemplate, err := template.ParseFiles(("stream.html")) + streamTemplate, err := template.ParseFiles(filepath.Join("templates", "stream.html")) if err != nil { log.Fatal(err) @@ -37,6 +38,9 @@ func stream(w http.ResponseWriter, r *http.Request) { } func main() { + staticFileServer := http.FileServer(http.Dir("./static")) + http.Handle("/static/", http.StripPrefix("/static/", staticFileServer)) + http.HandleFunc("/", index) http.HandleFunc("/stream", stream) log.Fatal(http.ListenAndServe(":8080", nil)) diff --git a/static/js/stream.js b/static/js/stream.js new file mode 100755 index 0000000..66d9aec --- /dev/null +++ b/static/js/stream.js @@ -0,0 +1 @@ +alert("test"); \ No newline at end of file diff --git a/index.html b/templates/index.html similarity index 100% rename from index.html rename to templates/index.html diff --git a/stream.html b/templates/stream.html similarity index 84% rename from stream.html rename to templates/stream.html index 2207758..345674c 100755 --- a/stream.html +++ b/templates/stream.html @@ -1,6 +1,6 @@ - + diff --git a/tmp/air_errors.log b/tmp/air_errors.log new file mode 100644 index 0000000..0427d98 --- /dev/null +++ b/tmp/air_errors.log @@ -0,0 +1 @@ +exit status 2exit status 2exit status 2exit status 2 \ No newline at end of file