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" : "{{ .BaseURL }}",
"type" : "io.artifacthub.{{ .Event.Kind }}",
"datacontenttype" : "application/json",
"data" : {
"package": {
"name": "{{ .Package.Name }}",
"version": "{{ .Package.Version }}",
"url": "{{ .Package.URL }}",
"changes": [{{range $i, $e := .Package.Changes}}{{if $i}}, {{end}}"{{.Description}}"{{end}}],
"containsSecurityUpdates": {{ .Package.ContainsSecurityUpdates }},
"prerelease": {{ .Package.Prerelease }},
"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(svc *Services, opts ...func(d *Dispatcher)) *Dispatcher
NewDispatcher creates a new Dispatcher instance.
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 { Cfg *viper.Viper DB hub.DB ES hub.EmailSender NotificationManager hub.NotificationManager SubscriptionManager hub.SubscriptionManager RepositoryManager hub.RepositoryManager PackageManager hub.PackageManager HTTPClient hub.HTTPClient }
Services is a wrapper around several internal services used to handle notifications deliveries.