Files
DiunDashboard/cmd/diunwebhook/main.go
Jean-Luc Makiola bf77142641
All checks were successful
CI / build-test (push) Successful in 1m3s
**feat(compose):** add separate deploy and dev Docker Compose files
- Introduced `compose.yml` for deployment, pulling the image from the registry
- Added `compose.dev.yml` for local development, building the image from source
- Updated `README.md` and `.claude/CLAUDE.md` with instructions for both configurations
- Introduced `DB_PATH` environment variable to customize SQLite database file location
- Updated `main.go` to use `DB_PATH` with a default fallback (`./diun.db`)
2026-02-27 15:11:47 +01:00

76 lines
1.7 KiB
Go

package main
import (
"context"
"errors"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"time"
diun "awesomeProject/pkg/diunwebhook"
)
func main() {
dbPath := os.Getenv("DB_PATH")
if dbPath == "" {
dbPath = "./diun.db"
}
if err := diun.InitDB(dbPath); err != nil {
log.Fatalf("InitDB: %v", err)
}
secret := os.Getenv("WEBHOOK_SECRET")
if secret == "" {
log.Println("WARNING: WEBHOOK_SECRET not set — webhook endpoint is unprotected")
} else {
diun.SetWebhookSecret(secret)
log.Println("Webhook endpoint protected with token authentication")
}
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
mux := http.NewServeMux()
mux.HandleFunc("/webhook", diun.WebhookHandler)
mux.HandleFunc("/api/updates/", diun.DismissHandler)
mux.HandleFunc("/api/updates", diun.UpdatesHandler)
mux.HandleFunc("/api/tags", diun.TagsHandler)
mux.HandleFunc("/api/tags/", diun.TagByIDHandler)
mux.HandleFunc("/api/tag-assignments", diun.TagAssignmentHandler)
mux.Handle("/", http.FileServer(http.Dir("./frontend/dist")))
srv := &http.Server{
Addr: ":" + port,
Handler: mux,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
IdleTimeout: 60 * time.Second,
}
stop := make(chan os.Signal, 1)
signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)
go func() {
log.Printf("Listening on :%s", port)
if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Fatalf("ListenAndServe: %v", err)
}
}()
<-stop
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
if err := srv.Shutdown(ctx); err != nil {
log.Printf("Shutdown error: %v", err)
} else {
log.Println("Server stopped cleanly")
}
}