added global vars for templates
This commit is contained in:
parent
69d30587cb
commit
df08e944b9
2 changed files with 9 additions and 2 deletions
7
main.go
7
main.go
|
@ -12,6 +12,9 @@ import (
|
||||||
"gocv.io/x/gocv"
|
"gocv.io/x/gocv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var indexHTML = filepath.Join("templates", "index.html")
|
||||||
|
var streamHTML = filepath.Join("templates", "stream.html")
|
||||||
|
|
||||||
// Server is the main application struct
|
// Server is the main application struct
|
||||||
type Server struct {
|
type Server struct {
|
||||||
Streams map[string]Stream
|
Streams map[string]Stream
|
||||||
|
@ -19,7 +22,7 @@ type Server struct {
|
||||||
|
|
||||||
func (server Server) index(w http.ResponseWriter, r *http.Request) {
|
func (server Server) index(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.FormValue("URL") == "" {
|
if r.FormValue("URL") == "" {
|
||||||
indexTemplate, err := template.ParseFiles(filepath.Join("templates", "index.html"))
|
indexTemplate, err := template.ParseFiles(indexHTML)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -33,7 +36,7 @@ func (server Server) index(w http.ResponseWriter, r *http.Request) {
|
||||||
server.Streams[URL] = stream
|
server.Streams[URL] = stream
|
||||||
go stream.Update()
|
go stream.Update()
|
||||||
}
|
}
|
||||||
streamTemplate, err := template.ParseFiles(filepath.Join("templates", "stream.html"))
|
streamTemplate, err := template.ParseFiles(streamHTML)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
<html>
|
<html>
|
||||||
|
<title>StreamWatcher</title>
|
||||||
|
<head>
|
||||||
|
|
||||||
|
</head>
|
||||||
<h1>Stream URL</h1>
|
<h1>Stream URL</h1>
|
||||||
<form method="GET">
|
<form method="GET">
|
||||||
<label>URL:</label>
|
<label>URL:</label>
|
||||||
|
|
Loading…
Add table
Reference in a new issue