This commit is contained in:
parent
b03404b2cc
commit
afbe9e74a5
2 changed files with 23 additions and 1 deletions
17
main.go
17
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)
|
||||
}
|
|
@ -19,5 +19,12 @@
|
|||
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
||||
}).addTo(map);
|
||||
|
||||
function update() {
|
||||
fetch('/json')
|
||||
.then(response => response.json())
|
||||
.then(data => console.log(data));
|
||||
}
|
||||
update()
|
||||
</script>
|
||||
</body>
|
Loading…
Reference in a new issue