Almost there
This commit is contained in:
10
server.go
10
server.go
@@ -13,11 +13,11 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const ROOT_URL = "/climate/"
|
const ROOT_URL = "/climate"
|
||||||
|
|
||||||
func startServer() {
|
func startServer() {
|
||||||
port := "8001"
|
port := "8001"
|
||||||
router := mux.NewRouter().StrictSlash(true)
|
router := mux.NewRouter()
|
||||||
router.HandleFunc("/show", showCharts).Methods("GET")
|
router.HandleFunc("/show", showCharts).Methods("GET")
|
||||||
router.HandleFunc("/show", showCharts).Methods("GET").Queries("show-minutes", "{[0-9]+}")
|
router.HandleFunc("/show", showCharts).Methods("GET").Queries("show-minutes", "{[0-9]+}")
|
||||||
router.HandleFunc("/data", sendData).Methods("GET")
|
router.HandleFunc("/data", sendData).Methods("GET")
|
||||||
@@ -33,12 +33,12 @@ func showCharts(w http.ResponseWriter, r *http.Request) {
|
|||||||
minutes := r.FormValue("show-minutes")
|
minutes := r.FormValue("show-minutes")
|
||||||
if minutes != "" {
|
if minutes != "" {
|
||||||
if _, err := strconv.ParseInt(minutes, 10, 0); err != nil {
|
if _, err := strconv.ParseInt(minutes, 10, 0); err != nil {
|
||||||
http.Redirect(w, r, ROOT_URL, 303)
|
http.Redirect(w, r, ROOT_URL + "/show", 303)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
templater, err := template.ParseFiles("webapp/dist/charts.html")
|
templater, err := template.ParseFiles("webapp/dist/charts.html")
|
||||||
if internalErrorOnErr(fmt.Errorf("couldn't parse the template: %w", err), w, r) { return }
|
if internalErrorOnErr(fmt.Errorf("couldn't parse the template: %w", err), w, r) { return }
|
||||||
err = templater.Execute(w, ROOT_URL)
|
err = templater.Execute(w, ROOT_URL + "/show")
|
||||||
internalErrorOnErr(err, w, r)
|
internalErrorOnErr(err, w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ func sendData(w http.ResponseWriter, r *http.Request) {
|
|||||||
if sinceQuery != "" {
|
if sinceQuery != "" {
|
||||||
newDateSince, err := time.Parse(time.RFC3339Nano, sinceQuery)
|
newDateSince, err := time.Parse(time.RFC3339Nano, sinceQuery)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Redirect(w, r, ROOT_URL, 303)
|
http.Redirect(w, r, ROOT_URL + "/show", 303)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
dateSince = strings.Split(newDateSince.Format(time.RFC3339Nano), "Z")[0]
|
dateSince = strings.Split(newDateSince.Format(time.RFC3339Nano), "Z")[0]
|
||||||
|
|||||||
Reference in New Issue
Block a user