Documentation ¶
Index ¶
Constants ¶
const ( // DefaultPayloadContentType represents the default content type used for // webhooks notifications. DefaultPayloadContentType = "application/cloudevents+json" )
Variables ¶
var DefaultWebhookPayloadTmpl = template.Must(template.New("").Parse(`
{
"specversion" : "1.0",
"id" : "{{ .Event.id }}",
"source" : "https://artifacthub.io/cloudevents",
"type" : "io.artifacthub.{{ .Event.kind }}",
"datacontenttype" : "application/json",
"data" : {
"package": {
"name": "{{ .Package.name }}",
"version": "{{ .Package.version }}",
"url": "{{ .Package.url }}",
"repository": {
"kind": "{{ .Package.repository.kind }}",
"name": "{{ .Package.repository.name }}",
"publisher": "{{ .Package.repository.publisher }}"
}
}
}
}
`))
DefaultWebhookPayloadTmpl is the template used for the webhook payload when the webhook uses the default template.
var ( // ErrRetryable is meant to be used as a wrapper for other errors to // indicate the error is not final and the operation should be retried. ErrRetryable = errors.New("retryable error") )
Functions ¶
func WithNumWorkers ¶
func WithNumWorkers(n int) func(d *Dispatcher)
WithNumWorkers allows providing a specific number of workers for a Dispatcher instance.
Types ¶
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher handles a group of workers in charge of delivering notifications.
func NewDispatcher ¶
func NewDispatcher(cfg *viper.Viper, svc *Services, opts ...func(d *Dispatcher)) *Dispatcher
NewDispatcher creates a new Dispatcher instance.
type HTTPClient ¶
HTTPClient defines the methods an HTTPClient implementation must provide.
type Manager ¶
type Manager struct{}
Manager provides an API to manage notifications.
func (*Manager) GetPending ¶
GetPending returns a pending notification to be delivered if available.
type ManagerMock ¶
ManagerMock is a mock implementation of the NotificationManager interface.
func (*ManagerMock) Add ¶
func (m *ManagerMock) Add(ctx context.Context, tx pgx.Tx, n *hub.Notification) error
Add implements the NotificationManager interface.
func (*ManagerMock) GetPending ¶
func (m *ManagerMock) GetPending(ctx context.Context, tx pgx.Tx) (*hub.Notification, error)
GetPending implements the NotificationManager interface.
func (*ManagerMock) UpdateStatus ¶
func (m *ManagerMock) UpdateStatus( ctx context.Context, tx pgx.Tx, notificationID string, processed bool, processedErr error, ) error
UpdateStatus implements the NotificationManager interface.
type Services ¶
type Services struct { DB hub.DB ES hub.EmailSender NotificationManager hub.NotificationManager SubscriptionManager hub.SubscriptionManager RepositoryManager hub.RepositoryManager PackageManager hub.PackageManager }
Services is a wrapper around several internal services used to handle notifications deliveries.
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker is in charge of delivering notifications to their intended recipients.