Code cleanup
parent
5b86e618fc
commit
ceb53970a1
|
@ -19,10 +19,15 @@ func handleReport(w http.ResponseWriter, r *http.Request) {
|
|||
switch action {
|
||||
|
||||
case "ping":
|
||||
_ = db.SourceUpdateLastSeenAt(src.SourceID)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
if err = db.SourceUpdateLastSeenAt(src.SourceID); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
} else {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
case "log":
|
||||
_ = db.SourceUpdateLastSeenAt(src.SourceID)
|
||||
|
||||
text := r.Form.Get("text")
|
||||
_ = db.LogInsert(Entry{
|
||||
SourceID: src.SourceID,
|
||||
|
@ -32,6 +37,8 @@ func handleReport(w http.ResponseWriter, r *http.Request) {
|
|||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
case "alert":
|
||||
_ = db.SourceUpdateLastSeenAt(src.SourceID)
|
||||
|
||||
text := r.Form.Get("text")
|
||||
_ = db.LogInsert(Entry{
|
||||
SourceID: src.SourceID,
|
||||
|
@ -40,5 +47,8 @@ func handleReport(w http.ResponseWriter, r *http.Request) {
|
|||
})
|
||||
runAlertAction(src.AlertAction, src.Name, text)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
default:
|
||||
http.Error(w, "Unknown action: "+action, http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue