feat: настраиваемые каналы уведомлений (telegram/pachca/email) с маршрутизацией по пути
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
32
handler.go
Normal file
32
handler.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// makeHandler возвращает http-хендлер, маршрутизирующий по первому сегменту пути.
|
||||
func makeHandler(notifiers map[string]Notifier) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
paths := strings.Split(r.URL.Path, "/")
|
||||
if len(paths) < 2 || paths[1] == "" {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
n, ok := notifiers[paths[1]]
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
data := ExtractRequest(r)
|
||||
if err := n.Send(data); err != nil {
|
||||
log.Println(err)
|
||||
w.WriteHeader(http.StatusBadGateway)
|
||||
_, _ = w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write([]byte("OK"))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user