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