???
This commit is contained in:
parent
ed57cbd884
commit
8f5da5e228
1 changed files with 22 additions and 8 deletions
30
main.go
30
main.go
|
@ -87,7 +87,12 @@ func index(w http.ResponseWriter, r *http.Request) {
|
|||
if (!accept_html || prefer_text) && accept_text {
|
||||
indexForVT100(w, r, data)
|
||||
} else if accept_html {
|
||||
indexForBrowser(w, r, data, config.SiteName, config.IconSrc)
|
||||
historical_data, err := dbm.QueryAllAfter(time.Now().Add(-7 * 24 * time.Hour))
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
}
|
||||
indexForBrowserWithHistoricalData(w, r, historical_data, config.SiteName, config.IconSrc)
|
||||
} else { // when no valid content type is requested
|
||||
// not to-spec. still sends plain text anyway
|
||||
indexForVT100(w, r, data)
|
||||
|
@ -100,14 +105,23 @@ func indexForVT100(w http.ResponseWriter, _ *http.Request, data scanner.ServiceS
|
|||
w.Write([]byte(parsedTemplate))
|
||||
}
|
||||
|
||||
func indexForBrowser(w http.ResponseWriter, _ *http.Request, data scanner.ServiceStatusBatch, siteName, iconSrc string) {
|
||||
parsedTemplate, err := parseAndRenderTemplate("templates/index.html", siteName, iconSrc, data)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
}
|
||||
// func indexForBrowser(w http.ResponseWriter, _ *http.Request, data scanner.ServiceStatusBatch, siteName string, iconSrc string) {
|
||||
// parsedTemplate, err := parseAndRenderTemplate("templates/index.html", siteName, iconSrc, data)
|
||||
// if err != nil {
|
||||
// http.Error(w, err.Error(), 500)
|
||||
// return
|
||||
// }
|
||||
|
||||
w.Write([]byte(parsedTemplate))
|
||||
// w.Write([]byte(parsedTemplate))
|
||||
// }
|
||||
|
||||
func indexForBrowserWithHistoricalData(w http.ResponseWriter, _ *http.Request, historical_data []core.Row, siteName string, iconSrc string) {
|
||||
// the basic idea here:
|
||||
// - create new template and render it with historical_data
|
||||
//
|
||||
// reference: see `indexForBrowser` above
|
||||
|
||||
panic("todo")
|
||||
}
|
||||
|
||||
var config *core.Config
|
||||
|
|
Loading…
Reference in a new issue