forked from sameerdhoot/wolweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpages.go
44 lines (36 loc) · 911 Bytes
/
pages.go
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
35
36
37
38
39
40
41
42
43
44
package main
import (
_ "embed"
"html/template"
"io"
"net/http"
"github.com/icefed/zlog"
)
//go:embed index.html
var indexHtml string
func renderHomePage(w http.ResponseWriter, r *http.Request) {
pageData := struct {
Devices []Device
VDir string
BCastIP string
ReadOnly bool
}{
Devices: appData.Devices,
VDir: appConfig.VDir,
BCastIP: appConfig.BCastIP,
ReadOnly: appConfig.ReadOnly,
}
if appConfig.VDir == "/" {
pageData.VDir = ""
}
tmpl, _ := template.New("index.html").Parse(indexHtml)
tmpl.Execute(w, pageData)
zlog.Info("Renedered the home page.")
}
func redirectToHomePage(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, appConfig.VDir+"/", http.StatusFound)
}
func checkHealth(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
io.WriteString(w, "alive")
}