initial hopefully work setup
This commit is contained in:
parent
ad8b83ac61
commit
6307923dd9
4 changed files with 70 additions and 38 deletions
30
server.go
Normal file
30
server.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func alertReceiver(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(io.LimitReader(r.Body, 1<<20))
|
||||
if err != nil {
|
||||
http.Error(w, "Payload exceeded maximum size. Are you really sending alerts?", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
defer r.Body.Close()
|
||||
|
||||
if len(body) == 0 {
|
||||
http.Error(w, "Empty payload", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
payload := ParseAlert(body)
|
||||
fmt.Printf(payload)
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue