57 lines
No EOL
1.1 KiB
Go
57 lines
No EOL
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
_ "embed"
|
|
"encoding/json"
|
|
"fmt"
|
|
"html/template"
|
|
"net/http"
|
|
)
|
|
|
|
var lastData map[string]interface{}
|
|
|
|
//go:embed notfall.tmpl
|
|
var templateContent []byte
|
|
|
|
|
|
func main() {
|
|
http.HandleFunc("/owntrack", func(writer http.ResponseWriter, request *http.Request) {
|
|
var p map[string]interface{}
|
|
err := json.NewDecoder(request.Body).Decode(&p)
|
|
if err != nil {
|
|
writer.WriteHeader(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
if p["_type"] == "location"{
|
|
lastData = p
|
|
}
|
|
|
|
fmt.Println(p)
|
|
|
|
writer.Write([]byte("[]"))
|
|
})
|
|
|
|
http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
|
|
templ := template.Must(template.New("page").Parse(string(templateContent)))
|
|
templ.Execute(writer, map[string]interface{}{
|
|
})
|
|
})
|
|
|
|
http.HandleFunc("/json", func(writer http.ResponseWriter, request *http.Request) {
|
|
data := make(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)
|
|
} |