Files
nexarch/cmd/notify-api/main.go
T

54 lines
1.5 KiB
Go

// notify-api ist der Aufrufpunkt fuer CFG-05: stellt Core CFG-04s
// EnqueueIfAllowed als HTTP-Endpunkt fuer andere, physisch getrennte
// Module (Archive, DMS, Mail) bereit. Getrennt von cmd/core aus
// demselben Grund wie policy-api (RBAC-06).
package main
import (
"context"
"log"
"net/http"
"os"
"github.com/jackc/pgx/v5/pgxpool"
"gitea.perlbach24.de/scripte/nexarch/internal/httpharden"
"gitea.perlbach24.de/scripte/nexarch/internal/notify"
"gitea.perlbach24.de/scripte/nexarch/internal/notifyapi"
"gitea.perlbach24.de/scripte/nexarch/internal/notifyprefs"
)
func main() {
dsn := os.Getenv("NEXARCH_NOTIFY_ADMIN_DSN")
if dsn == "" {
log.Fatal("NEXARCH_NOTIFY_ADMIN_DSN muss gesetzt sein")
}
serviceToken := os.Getenv("NEXARCH_NOTIFY_SERVICE_TOKEN")
if serviceToken == "" {
log.Fatal("NEXARCH_NOTIFY_SERVICE_TOKEN muss gesetzt sein")
}
addr := os.Getenv("NEXARCH_NOTIFY_API_LISTEN_ADDR")
if addr == "" {
addr = "127.0.0.1:8094"
}
ctx := context.Background()
pool, err := pgxpool.New(ctx, dsn)
if err != nil {
log.Fatalf("datenbankverbindung: %v", err)
}
defer pool.Close()
prefs := notifyprefs.NewStore(pool)
dispatcher := notify.NewDispatcher(pool)
mux := http.NewServeMux()
notifyapi.Mount(mux, prefs, dispatcher, serviceToken)
mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) })
log.Printf("notify-api: listening on %s", addr)
if err := httpharden.ListenAndServe(addr, mux); err != nil {
log.Fatalf("http server: %v", err)
}
}