From 79273b2c0dbca77bef3e6612f35506de52a1d895 Mon Sep 17 00:00:00 2001 From: BroodjeAap Date: Thu, 9 Jul 2020 19:31:00 +0000 Subject: [PATCH] added base html template --- main.go | 5 +++-- templates/base.html | 10 ++++++++++ templates/index.html | 19 ++++++++----------- templates/stream.html | 14 ++++---------- 4 files changed, 25 insertions(+), 23 deletions(-) create mode 100755 templates/base.html diff --git a/main.go b/main.go index 84d0c41..dbc53c4 100755 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ import ( "gocv.io/x/gocv" ) +var baseHTML = filepath.Join("templates", "base.html") var indexHTML = filepath.Join("templates", "index.html") var streamHTML = filepath.Join("templates", "stream.html") @@ -22,7 +23,7 @@ type Server struct { func (server Server) index(w http.ResponseWriter, r *http.Request) { if r.FormValue("URL") == "" { - indexTemplate, err := template.ParseFiles(indexHTML) + indexTemplate, err := template.ParseFiles(indexHTML, baseHTML) if err != nil { log.Fatal(err) } @@ -36,7 +37,7 @@ func (server Server) index(w http.ResponseWriter, r *http.Request) { server.Streams[URL] = stream go stream.Update() } - streamTemplate, err := template.ParseFiles(streamHTML) + streamTemplate, err := template.ParseFiles(streamHTML, baseHTML) if err != nil { log.Fatal(err) diff --git a/templates/base.html b/templates/base.html new file mode 100755 index 0000000..c8e74fb --- /dev/null +++ b/templates/base.html @@ -0,0 +1,10 @@ +{{define "base"}} + + + StreamWatcher + + + {{template "content" .}} + + +{{end}} \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 0f57dc9..8c175ba 100755 --- a/templates/index.html +++ b/templates/index.html @@ -1,11 +1,8 @@ - - StreamWatcher - - - -

Stream URL

-
- - -
- \ No newline at end of file +{{template "base" .}} +{{define "content"}} +

Stream URL

+
+ + +
+{{end}} \ No newline at end of file diff --git a/templates/stream.html b/templates/stream.html index 9af9cf5..aa28283 100755 --- a/templates/stream.html +++ b/templates/stream.html @@ -1,10 +1,4 @@ - - - - - - - - - - \ No newline at end of file +{{template "base" .}} +{{define "content"}} + +{{end}} \ No newline at end of file