initial
This commit is contained in:
parent
566c2a1a76
commit
e5a70b9e91
9 changed files with 298 additions and 31 deletions
31
server.go
Normal file
31
server.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
|
||||
func (cfg *Config) 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)
|
||||
publish := sendAlerts(cfg, payload)
|
||||
check(publish)
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue