Changed endpoints and db queries, chart now shows suggested mins and maxes
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/gorilla/mux"
|
||||
@@ -11,6 +10,7 @@ import (
|
||||
)
|
||||
|
||||
const DEBUG = true
|
||||
const ROOT_URL = "climate/"
|
||||
|
||||
func main() {
|
||||
err := setup()
|
||||
@@ -41,7 +41,7 @@ func startServer() {
|
||||
r.HandleFunc("/data/since/{mins}", sendData).Methods("GET")
|
||||
r.HandleFunc("/data/last/", sendLastSnapshot).Methods("GET")
|
||||
r.HandleFunc("/", saveSnapshot).Methods("POST")
|
||||
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("static/"))))
|
||||
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir(ROOT_URL + "static/"))))
|
||||
http.Handle("/", r)
|
||||
fmt.Printf("Listening on port %s...\n", port)
|
||||
log.Fatal(http.ListenAndServe(":"+port, nil))
|
||||
@@ -50,7 +50,7 @@ func startServer() {
|
||||
func showCharts(w http.ResponseWriter, r *http.Request) {
|
||||
if countStr := mux.Vars(r)["mins"]; countStr != "" {
|
||||
if _, err := strconv.ParseInt(countStr, 10, 0); err != nil {
|
||||
http.Redirect(w, r, "/", 303)
|
||||
http.Redirect(w, r, ROOT_URL + "/", 303)
|
||||
}
|
||||
}
|
||||
http.ServeFile(w, r, "charts.html")
|
||||
@@ -61,8 +61,7 @@ func sendData(w http.ResponseWriter, r *http.Request) {
|
||||
if vars := mux.Vars(r); vars["mins"] != "" {
|
||||
newCount, err := strconv.ParseInt(vars["mins"], 10, 0)
|
||||
if err != nil {
|
||||
sendInternalError(errors.New("bad snapshot count request"), w, r)
|
||||
return
|
||||
http.Redirect(w, r, ROOT_URL + "/", 303)
|
||||
}
|
||||
count = newCount
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user