added base html template
This commit is contained in:
parent
df08e944b9
commit
79273b2c0d
4 changed files with 25 additions and 23 deletions
5
main.go
5
main.go
|
@ -12,6 +12,7 @@ import (
|
||||||
"gocv.io/x/gocv"
|
"gocv.io/x/gocv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var baseHTML = filepath.Join("templates", "base.html")
|
||||||
var indexHTML = filepath.Join("templates", "index.html")
|
var indexHTML = filepath.Join("templates", "index.html")
|
||||||
var streamHTML = filepath.Join("templates", "stream.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) {
|
func (server Server) index(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.FormValue("URL") == "" {
|
if r.FormValue("URL") == "" {
|
||||||
indexTemplate, err := template.ParseFiles(indexHTML)
|
indexTemplate, err := template.ParseFiles(indexHTML, baseHTML)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -36,7 +37,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(streamHTML)
|
streamTemplate, err := template.ParseFiles(streamHTML, baseHTML)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|
10
templates/base.html
Executable file
10
templates/base.html
Executable file
|
@ -0,0 +1,10 @@
|
||||||
|
{{define "base"}}
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>StreamWatcher</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{{template "content" .}}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
{{end}}
|
|
@ -1,11 +1,8 @@
|
||||||
<html>
|
{{template "base" .}}
|
||||||
<title>StreamWatcher</title>
|
{{define "content"}}
|
||||||
<head>
|
<h1>Stream URL</h1>
|
||||||
|
<form method="GET">
|
||||||
</head>
|
|
||||||
<h1>Stream URL</h1>
|
|
||||||
<form method="GET">
|
|
||||||
<label>URL:</label>
|
<label>URL:</label>
|
||||||
<input type="text" name="URL" size="100">
|
<input type="text" name="URL" size="100">
|
||||||
</form>
|
</form>
|
||||||
</html>
|
{{end}}
|
|
@ -1,10 +1,4 @@
|
||||||
<html>
|
{{template "base" .}}
|
||||||
<head>
|
{{define "content"}}
|
||||||
<script src="/static/js/stream.js"></script>
|
<img src="/stream?URL={{.URL}}">
|
||||||
<link rel="stylesheet" href="/static/css/style.css">
|
{{end}}
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<img src="/stream?URL={{.URL}}">
|
|
||||||
</body>
|
|
||||||
</html>
|
|
Loading…
Add table
Reference in a new issue