notfall/main.go

42 lines
796 B
Go
Raw Normal View History

2022-01-16 10:55:37 +00:00
package main
import (
2022-01-16 11:27:54 +00:00
_ "embed"
2022-01-16 10:55:37 +00:00
"encoding/json"
"fmt"
2022-01-16 11:27:54 +00:00
"html/template"
2022-01-16 10:55:37 +00:00
"net/http"
)
var lastData interface{}
2022-01-16 11:27:54 +00:00
//go:embed notfall.tmpl
var templateContent []byte
2022-01-16 10:55:37 +00:00
func main() {
http.HandleFunc("/owntrack", func(writer http.ResponseWriter, request *http.Request) {
2022-01-16 11:27:54 +00:00
var p map[string]interface{}
2022-01-16 10:55:37 +00:00
err := json.NewDecoder(request.Body).Decode(&p)
if err != nil {
2022-01-16 10:56:34 +00:00
writer.WriteHeader(http.StatusInternalServerError)
return
2022-01-16 10:55:37 +00:00
}
2022-01-16 11:27:54 +00:00
if p["_type"] == "location"{
lastData = p
}
2022-01-16 10:55:37 +00:00
fmt.Println(p)
2022-01-16 11:27:54 +00:00
writer.Write([]byte("[]"))
2022-01-16 10:55:37 +00:00
})
http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
2022-01-16 11:27:54 +00:00
templ := template.Must(template.New("page").Parse(string(templateContent)))
templ.Execute(writer, map[string]interface{}{
})
2022-01-16 10:55:37 +00:00
})
http.ListenAndServe(":8080", nil)
}