service

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package service provides the webhook business logic layer.

Index

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

func WithConfig(cfg Config) Option

WithConfig sets the configuration for the service.

func WithLogger

func WithLogger(logger Logger) Option

WithLogger sets the logger 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

func (s *WebhookService) DeliverWebhooksForEvent(ctx context.Context, event bus.Event) error

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

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL