From c825ccbb0e387863a774ca777c348103eff6e137 Mon Sep 17 00:00:00 2001 From: kekskurse Date: Sun, 16 Jan 2022 13:12:21 +0100 Subject: [PATCH] Stuff --- main.go | 15 +++++++++++++++ notfall.tmpl | 13 +++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 87426d3..81324cc 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "encoding/json" "html/template" "net/http" + "time" ) var lastData map[string]interface{} @@ -13,6 +14,7 @@ var lastData map[string]interface{} var templateContent []byte var active = false +var activeSince time.Time var getData = false @@ -40,11 +42,24 @@ func main() { }) }) + http.HandleFunc("/activate", func(writer http.ResponseWriter, request *http.Request) { + active = true + activeSince = time.Now() + }) + http.HandleFunc("/json", func(writer http.ResponseWriter, request *http.Request) { if getData == false || active == false { writer.WriteHeader(http.StatusInternalServerError) return } + + diff := time.Now().Sub(activeSince) + if diff.Minutes() > 2 { + active = false + writer.WriteHeader(http.StatusInternalServerError) + return + } + data := make(map[string]interface{}) data["lat"] = lastData["lat"] diff --git a/notfall.tmpl b/notfall.tmpl index dd15fe9..c15329b 100644 --- a/notfall.tmpl +++ b/notfall.tmpl @@ -15,18 +15,23 @@
Last Update: +Es gibt einen Notfall, zeige mir den standort an, eine sms mit einer benachrichtung wird gesendet +