Documentation
¶
Overview ¶
Package service provides the webhook business logic layer.
Index ¶
- type Config
- type Logger
- type Option
- type RegisterWebhookRequest
- type UpdateWebhookRequest
- type WebhookService
- func (s *WebhookService) DeleteWebhook(ctx context.Context, webhookID string) error
- func (s *WebhookService) DeliverWebhooksForEvent(ctx context.Context, event bus.Event) error
- func (s *WebhookService) DisableWebhook(ctx context.Context, webhookID string) error
- func (s *WebhookService) GetDeliveries(ctx context.Context, webhookID string, filter repository.DeliveryFilter) ([]repository.WebhookDelivery, error)
- func (s *WebhookService) GetWebhook(ctx context.Context, webhookID string) (*repository.WebhookConfig, error)
- func (s *WebhookService) ListWebhooks(ctx context.Context, filter repository.WebhookFilter) ([]repository.WebhookConfig, error)
- func (s *WebhookService) RegisterWebhook(ctx context.Context, req RegisterWebhookRequest) (string, error)
- func (s *WebhookService) RetryFailedWebhook(ctx context.Context, deliveryID string) error
- func (s *WebhookService) SendTestWebhook(ctx context.Context, webhookID string) (*repository.WebhookDelivery, error)
- func (s *WebhookService) UpdateWebhook(ctx context.Context, webhookID string, req UpdateWebhookRequest) error
- func (s *WebhookService) ValidateWebhookURL(ctx context.Context, url string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
MaxFailureCount int // Disable webhook after this many consecutive failures
DefaultTimeout time.Duration // Default timeout for webhook delivery
}
Config holds configuration for the webhook service.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a default service configuration.
type Logger ¶
type Logger interface {
Info(msg string, args ...any)
Error(msg string, args ...any)
Debug(msg string, args ...any)
Warn(msg string, args ...any)
}
Logger defines the logging interface for the webhook service.
type Option ¶
type Option func(*WebhookService)
Option configures the WebhookService.
func WithConfig ¶
WithConfig sets the configuration for the service.
type RegisterWebhookRequest ¶
type RegisterWebhookRequest struct {
URL string `json:"url" validate:"required,url"`
Events []bus.EventType `json:"events"`
Secret string `json:"secret,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
RegisterWebhookRequest represents a request to register a new webhook.
type UpdateWebhookRequest ¶
type UpdateWebhookRequest struct {
URL *string `json:"url,omitempty"`
Events []bus.EventType `json:"events,omitempty"`
Secret *string `json:"secret,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
Active *bool `json:"active,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
UpdateWebhookRequest represents a request to update a webhook.
type WebhookService ¶
type WebhookService struct {
// contains filtered or unexported fields
}
WebhookService orchestrates webhook delivery and management.
func NewWebhookService ¶
func NewWebhookService( client *webhook.Client, repo repository.WebhookRepository, opts ...Option, ) *WebhookService
NewWebhookService creates a new webhook service.
func (*WebhookService) DeleteWebhook ¶
func (s *WebhookService) DeleteWebhook(ctx context.Context, webhookID string) error
DeleteWebhook removes a webhook subscription.
func (*WebhookService) DeliverWebhooksForEvent ¶
DeliverWebhooksForEvent sends webhooks to all subscribed endpoints for an event.
func (*WebhookService) DisableWebhook ¶
func (s *WebhookService) DisableWebhook(ctx context.Context, webhookID string) error
DisableWebhook disables a webhook that has been failing.
func (*WebhookService) GetDeliveries ¶
func (s *WebhookService) GetDeliveries(ctx context.Context, webhookID string, filter repository.DeliveryFilter) ([]repository.WebhookDelivery, error)
GetDeliveries retrieves delivery history for a webhook.
func (*WebhookService) GetWebhook ¶
func (s *WebhookService) GetWebhook(ctx context.Context, webhookID string) (*repository.WebhookConfig, error)
GetWebhook retrieves a webhook by its ID.
func (*WebhookService) ListWebhooks ¶
func (s *WebhookService) ListWebhooks(ctx context.Context, filter repository.WebhookFilter) ([]repository.WebhookConfig, error)
ListWebhooks retrieves all webhooks with optional filtering.
func (*WebhookService) RegisterWebhook ¶
func (s *WebhookService) RegisterWebhook(ctx context.Context, req RegisterWebhookRequest) (string, error)
RegisterWebhook creates a new webhook subscription.
func (*WebhookService) RetryFailedWebhook ¶
func (s *WebhookService) RetryFailedWebhook(ctx context.Context, deliveryID string) error
RetryFailedWebhook retries a failed delivery.
func (*WebhookService) SendTestWebhook ¶
func (s *WebhookService) SendTestWebhook(ctx context.Context, webhookID string) (*repository.WebhookDelivery, error)
SendTestWebhook sends a test event to a webhook to verify it's working.
func (*WebhookService) UpdateWebhook ¶
func (s *WebhookService) UpdateWebhook(ctx context.Context, webhookID string, req UpdateWebhookRequest) error
UpdateWebhook updates a webhook configuration.
func (*WebhookService) ValidateWebhookURL ¶
func (s *WebhookService) ValidateWebhookURL(ctx context.Context, url string) error
ValidateWebhookURL verifies that a webhook endpoint is reachable.