feat: настраиваемые каналы уведомлений (telegram/pachca/email) с маршрутизацией по пути

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Vladimir V Maksimov
2026-06-14 11:10:44 +03:00
parent cfc9e23697
commit a21bb73175
6 changed files with 413 additions and 96 deletions

32
handler.go Normal file
View 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"))
}
}