adding api/v2 endpoints
All checks were successful
Check scripts syntax / check-scripts-syntax (push) Successful in 3s
Haven Notify Build and Deploy / Test Haven Notify (push) Successful in 46s
Haven Notify Build and Deploy / Build Haven Notify Image (PR) (push) Has been skipped
Haven Notify Build and Deploy / Build Haven Notify Image (push) Successful in 20s
Haven Notify Build and Deploy / Deploy Haven Notify (internal) (push) Successful in 3s

This commit is contained in:
2026-07-16 09:51:53 -03:00
parent f202be458a
commit 8db1db888f
6 changed files with 811 additions and 5 deletions

View File

@@ -32,12 +32,14 @@ type applicationConfig struct {
HTTPClient *http.Client
Sleep sleepFunc
Logger *log.Logger
Now func() time.Time
}
type application struct {
discord *discordClient
renderer *templateRenderer
logger *log.Logger
now func() time.Time
}
type notificationRequest struct {
@@ -77,6 +79,10 @@ func newApplication(cfg applicationConfig) (*application, error) {
if logger == nil {
logger = log.New(io.Discard, "", 0)
}
now := cfg.Now
if now == nil {
now = time.Now
}
renderer, err := newTemplateRenderer()
if err != nil {
@@ -88,7 +94,7 @@ func newApplication(cfg applicationConfig) (*application, error) {
return nil, err
}
return &application{discord: discord, renderer: renderer, logger: logger}, nil
return &application{discord: discord, renderer: renderer, logger: logger, now: now}, nil
}
func (a *application) handler() http.Handler {
@@ -97,6 +103,10 @@ func (a *application) handler() http.Handler {
mux.HandleFunc("/template/notify/backup", a.requireMethod(http.MethodPost, a.backupHandler))
mux.HandleFunc("/template/notify/update", a.requireMethod(http.MethodPost, a.updateHandler))
mux.HandleFunc("/template/notify/error", a.requireMethod(http.MethodPost, a.errorHandler))
mux.HandleFunc("/api/v2/messages", a.requireMethod(http.MethodPost, a.v2MessageHandler))
mux.HandleFunc("/api/v2/notifications/backup", a.requireMethod(http.MethodPost, a.v2BackupHandler))
mux.HandleFunc("/api/v2/notifications/update", a.requireMethod(http.MethodPost, a.v2UpdateHandler))
mux.HandleFunc("/api/v2/notifications/error", a.requireMethod(http.MethodPost, a.v2ErrorHandler))
mux.HandleFunc("/ready", a.requireProbeMethod(a.readinessHandler))
mux.HandleFunc("/live", a.requireProbeMethod(a.livenessHandler))
mux.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {