added visualisation
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/gorilla/mux"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const DEBUG = true
|
||||
@@ -34,7 +36,7 @@ func startServer() {
|
||||
port := "8001"
|
||||
r := mux.NewRouter()
|
||||
r.HandleFunc("/", showCharts).Methods("GET")
|
||||
r.HandleFunc("/data/", sendData).Methods("GET")
|
||||
r.HandleFunc("/data/{count}", sendData).Methods("GET")
|
||||
r.HandleFunc("/", saveSnapshot).Methods("POST")
|
||||
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("static/"))))
|
||||
http.Handle("/", r)
|
||||
@@ -47,7 +49,17 @@ func showCharts(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 {
|
||||
sendInternalError(fmt.Errorf("couldn't read rows from the database: %w", err), w, r)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user