diff --git a/main.go b/main.go index 35b4480..65474f1 100644 --- a/main.go +++ b/main.go @@ -8,7 +8,7 @@ import ( "net/http" ) -var lastData interface{} +var lastData map[string]interface{} //go:embed notfall.tmpl var templateContent []byte @@ -38,5 +38,20 @@ func main() { }) }) + http.HandleFunc("/json", func(writer http.ResponseWriter, request *http.Request) { + var data map[string]interface{} + + data["lat"] = lastData["lat"] + data["lon"] = lastData["lon"] + data["tst"] = lastData["tst"] + + r, err := json.Marshal(data) + if err != nil { + panic(err) + } + + writer.Write(r) + }) + http.ListenAndServe(":8080", nil) } \ No newline at end of file diff --git a/notfall.tmpl b/notfall.tmpl index d1f488f..42e2631 100644 --- a/notfall.tmpl +++ b/notfall.tmpl @@ -19,5 +19,12 @@ L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© OpenStreetMap contributors' }).addTo(map); + + function update() { + fetch('/json') + .then(response => response.json()) + .then(data => console.log(data)); + } + update() \ No newline at end of file