mirror of
https://github.com/eduardolat/pgbackweb.git
synced 2026-04-25 05:35:57 +03:00
[PR #158] Customizable Webhook Body Templating #168
Labels
No labels
bug
confirmed next step
duplicate
enhancement
help wanted
in progress
in progress
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/pgbackweb#168
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/eduardolat/pgbackweb/pull/158
Author: @Ragug
Created: 12/1/2025
Status: 🔄 Open
Base:
develop← Head:feature/webhook-body-templating📝 Commits (1)
c489c90feat: Allow customizable webhook body using Go templates📊 Changes
10 files changed (+500 additions, -38 deletions)
View changed files
📝
internal/service/databases/test_database.go(+54 -2)📝
internal/service/destinations/test_destination.go(+45 -2)📝
internal/service/executions/run_execution.go(+51 -11)📝
internal/service/executions/run_execution.sql(+4 -0)➕
internal/service/webhooks/payload.go(+69 -0)📝
internal/service/webhooks/run_webhook.go(+31 -13)📝
internal/service/webhooks/send_webhook_request.go(+9 -2)➕
internal/service/webhooks/utils.go(+129 -0)📝
internal/view/web/dashboard/webhooks/common.go(+104 -7)📝
internal/view/web/dashboard/webhooks/run_webhook.go(+4 -1)📄 Description
🚀 Pull Request: Customizable Webhook Body Templating
This PR introduces the ability to use Go's
text/templatesyntax to define the JSON body of outgoing webhooks, replacing the previous static body or simple JSON object.This feature is inspired by the highly flexible and customizable webhook payloads found in professional monitoring and visualization tools like Uptime Kuma and Grafana, ensuring
pgbackwebcan integrate seamlessly with virtually any external notification system.This change required a comprehensive refactoring of the webhook data flow to ensure all necessary event context is correctly built and passed down to the rendering layer.
✨ Key Changes & Features
1. Customizable Webhook Body
Bodyfield for a webhook now accepts a Gotext/templatestring.formatTime,formatFileSize) are exposed in the template context for easy data formatting.2. Standardized Event Payloads
To support templating, the webhook data flow was standardized using three new structs:
internal/service/webhooks/payload.go: Defines the new payload structures:DatabaseStatusDestinationStatusExecutionDetailsWebhookPayload: The main struct passed to the template, containing the above three structs plusEventTypeandMsg.3. Refactored Service Runners
RunDatabaseHealthy,RunDestinationUnhealthy,RunExecutionSuccess, etc.) are updated across the application to pre-build and pass the detailedDatabaseStatus,DestinationStatus, or fullWebhookPayload.4. Improved UI Documentation
.Database.Name,.Execution.FileSize, etc.), provides syntax examples, and documents the available helper functions.💻 Code Changes & Technical Notes
internal/service/webhooks/payload.go(NEW)internal/service/webhooks/utils.go(NEW)ParsePostgresURL,RenderWebhookBody, andbuildMessage. Registers template functions likeformatFileSize.internal/service/{databases, destinations, executions}internal/service/webhooks/run_webhook.gorunWebhookto accept and use theWebhookPayload.internal/service/webhooks/send_webhook_request.goRenderWebhookBodyto transform the template string into the final HTTP body.internal/view/web/dashboard/webhooks/common.go💬 Maintainer Feedback and Review Notes ⚙️
This feature represents a massive and necessary improvement to the maintainability and flexibility of the webhook system.
The core motivation for this refactor—to eliminate the burden of configuring and maintaining separate, hard-coded JSON payloads for every database and status change—has been successfully addressed by introducing centralized templating. This vastly reduces overhead for administrators.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.