aboutsummaryrefslogtreecommitdiff
path: root/watch.go
blob: 8352e62473f2e5c227cbd9acafa34b02bccf96f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main

import (
	"html/template"
	"net/http"
)

var templateWatchFiles = []string{ "templates/base.html", "templates/watch.html" }
var templateWatch = template.Must(template.ParseFiles(templateWatchFiles...))

/* render template */
type WatchTemplateData struct {
	Id string
}

func renderWatchTemplate(w http.ResponseWriter, id string) {
	if debug {
		reloadTemplate(&templateWatch, templateWatchFiles...)
	}
	err := templateWatch.Execute(w, WatchTemplateData{
		Id: id,
	})
	if err != nil {
		templateError(err, w)
	}
}

/* routes */
func setupRoutesWatch() {
	http.HandleFunc("/watch", func(w http.ResponseWriter, r *http.Request) {
		id := r.URL.Query().Get("v")
		renderWatchTemplate(w, id)
	})
}