webhook

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: GPL-3.0 Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package webhook provides public types and helpers reusable across the codebase.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWebhookNotFound   = fmt.Errorf("%w: webhook not found", shared.ErrNotFound)
	ErrWebhookNameExists = fmt.Errorf("%w: webhook name already exists", shared.ErrAlreadyExists)
)

Functions

This section is empty.

Types

type Delivery

type Delivery struct {
	ID              ID
	WebhookID       ID
	EventID         *ID
	EventType       string
	Payload         map[string]any
	Status          DeliveryStatus
	ResponseCode    *int
	ResponseBody    string
	ResponseHeaders map[string]any
	Attempt         int
	NextRetryAt     *time.Time
	ErrorMessage    string
	CreatedAt       time.Time
	DeliveredAt     *time.Time
	DurationMs      *int
}

Delivery represents a webhook delivery attempt.

type DeliveryFilter

type DeliveryFilter struct {
	WebhookID *ID
	Status    *DeliveryStatus
	Page      int
	PerPage   int
}

DeliveryFilter represents filtering options for listing deliveries.

type DeliveryListResult

type DeliveryListResult struct {
	Data       []*Delivery
	Total      int64
	Page       int
	PerPage    int
	TotalPages int
}

DeliveryListResult represents a paginated list of deliveries.

type DeliveryStatus

type DeliveryStatus string

DeliveryStatus represents delivery status.

const (
	DeliveryPending  DeliveryStatus = "pending"
	DeliverySuccess  DeliveryStatus = "success"
	DeliveryFailed   DeliveryStatus = "failed"
	DeliveryRetrying DeliveryStatus = "retrying"
)

type Filter

type Filter struct {
	TenantID  *ID
	Status    *Status
	EventType string
	Search    string
	Page      int
	PerPage   int
	SortBy    string
	SortOrder string
}

Filter represents filtering options for listing webhooks.

type ID

type ID = shared.ID

ID is a type alias for shared.ID.

type ListResult

type ListResult struct {
	Data       []*Webhook
	Total      int64
	Page       int
	PerPage    int
	TotalPages int
}

ListResult represents a paginated list of webhooks.

type Repository

type Repository interface {
	Create(ctx context.Context, w *Webhook) error
	GetByID(ctx context.Context, id, tenantID ID) (*Webhook, error)
	List(ctx context.Context, filter Filter) (ListResult, error)
	Update(ctx context.Context, w *Webhook) error
	Delete(ctx context.Context, id, tenantID ID) error
	ListDeliveries(ctx context.Context, filter DeliveryFilter) (DeliveryListResult, error)
}

Repository defines the interface for webhook persistence.

type Status

type Status string

Status represents the webhook status.

const (
	StatusActive   Status = "active"
	StatusDisabled Status = "disabled"
	StatusError    Status = "error"
)

func (Status) IsValid

func (s Status) IsValid() bool

IsValid returns true if the status is valid.

type Webhook

type Webhook struct {
	// contains filtered or unexported fields
}

Webhook represents an outgoing webhook configuration.

func NewWebhook

func NewWebhook(id, tenantID ID, name, url string, eventTypes []string) *Webhook

NewWebhook creates a new webhook entity.

func Reconstruct

func Reconstruct(
	id, tenantID ID,
	name, description, url string,
	secretEncrypted []byte,
	eventTypes []string,
	severityThreshold string,
	assetGroupIDs, tags []string,
	status Status,
	maxRetries, retryIntervalSeconds int,
	totalSent, totalFailed int,
	lastSentAt *time.Time,
	lastError string,
	lastErrorAt *time.Time,
	createdBy *ID,
	createdAt, updatedAt time.Time,
) *Webhook

Reconstruct creates a Webhook from stored data.

func (*Webhook) AssetGroupIDs

func (w *Webhook) AssetGroupIDs() []string

func (*Webhook) CreatedAt

func (w *Webhook) CreatedAt() time.Time

func (*Webhook) CreatedBy

func (w *Webhook) CreatedBy() *ID

func (*Webhook) Description

func (w *Webhook) Description() string

func (*Webhook) Disable

func (w *Webhook) Disable()

Disable disables the webhook.

func (*Webhook) Enable

func (w *Webhook) Enable()

Enable enables the webhook.

func (*Webhook) EventTypes

func (w *Webhook) EventTypes() []string

func (*Webhook) ID

func (w *Webhook) ID() ID

func (*Webhook) LastError

func (w *Webhook) LastError() string

func (*Webhook) LastErrorAt

func (w *Webhook) LastErrorAt() *time.Time

func (*Webhook) LastSentAt

func (w *Webhook) LastSentAt() *time.Time

func (*Webhook) MaxRetries

func (w *Webhook) MaxRetries() int

func (*Webhook) Name

func (w *Webhook) Name() string

func (*Webhook) RetryIntervalSeconds

func (w *Webhook) RetryIntervalSeconds() int

func (*Webhook) SecretEncrypted

func (w *Webhook) SecretEncrypted() []byte

func (*Webhook) SetCreatedBy

func (w *Webhook) SetCreatedBy(id ID)

func (*Webhook) SetDescription

func (w *Webhook) SetDescription(desc string)

func (*Webhook) SetEventTypes

func (w *Webhook) SetEventTypes(types []string)

func (*Webhook) SetMaxRetries

func (w *Webhook) SetMaxRetries(n int)

func (*Webhook) SetName

func (w *Webhook) SetName(name string)

func (*Webhook) SetRetryIntervalSeconds

func (w *Webhook) SetRetryIntervalSeconds(n int)

func (*Webhook) SetSecret

func (w *Webhook) SetSecret(secret []byte)

func (*Webhook) SetSeverityThreshold

func (w *Webhook) SetSeverityThreshold(s string)

func (*Webhook) SetURL

func (w *Webhook) SetURL(url string)

func (*Webhook) SeverityThreshold

func (w *Webhook) SeverityThreshold() string

func (*Webhook) Status

func (w *Webhook) Status() Status

func (*Webhook) Tags

func (w *Webhook) Tags() []string

func (*Webhook) TenantID

func (w *Webhook) TenantID() ID

func (*Webhook) TotalFailed

func (w *Webhook) TotalFailed() int

func (*Webhook) TotalSent

func (w *Webhook) TotalSent() int

func (*Webhook) URL

func (w *Webhook) URL() string

func (*Webhook) UpdatedAt

func (w *Webhook) UpdatedAt() time.Time

Jump to

Keyboard shortcuts

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