added visualisation
This commit is contained in:
@@ -1,11 +1,13 @@
|
|||||||
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"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
const DEBUG = true
|
const DEBUG = true
|
||||||
@@ -34,7 +36,7 @@ func startServer() {
|
|||||||
port := "8001"
|
port := "8001"
|
||||||
r := mux.NewRouter()
|
r := mux.NewRouter()
|
||||||
r.HandleFunc("/", showCharts).Methods("GET")
|
r.HandleFunc("/", showCharts).Methods("GET")
|
||||||
r.HandleFunc("/data/", sendData).Methods("GET")
|
r.HandleFunc("/data/{count}", sendData).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("static/"))))
|
||||||
http.Handle("/", r)
|
http.Handle("/", r)
|
||||||
@@ -47,7 +49,17 @@ func showCharts(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func sendData(w http.ResponseWriter, r *http.Request) {
|
func sendData(w http.ResponseWriter, r *http.Request) {
|
||||||
records, err := getSnapshotRecordsFromDb(50)
|
vars := mux.Vars(r)
|
||||||
|
var count int64 = 50
|
||||||
|
if vars["count"] != "" {
|
||||||
|
newCount, err := strconv.ParseInt(vars["count"], 10, 0)
|
||||||
|
if err != nil {
|
||||||
|
sendInternalError(errors.New("bad snapshot count request"), w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
count = newCount
|
||||||
|
}
|
||||||
|
records, err := getSnapshotRecordsFromDb(int(count))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
sendInternalError(fmt.Errorf("couldn't read rows from the database: %w", err), w, r)
|
sendInternalError(fmt.Errorf("couldn't read rows from the database: %w", err), w, r)
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user