Help us shape the future of Go! Take the 2026 Go Developer Survey

webhook

package
v3.1.46 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DeliveryAttempt

type DeliveryAttempt struct {
	AttemptNumber int           `json:"attempt_number"`
	StatusCode    int           `json:"status_code,omitempty"`
	Error         string        `json:"error,omitempty"`
	Duration      time.Duration `json:"duration"`
	Timestamp     time.Time     `json:"timestamp"`
	NextRetryAt   *time.Time    `json:"next_retry_at,omitempty"`
}

DeliveryAttempt represents a single webhook delivery attempt

type DeliveryResult

type DeliveryResult struct {
	Success      bool              `json:"success"`
	Attempts     []DeliveryAttempt `json:"attempts"`
	FinalStatus  int               `json:"final_status,omitempty"`
	FinalError   string            `json:"final_error,omitempty"`
	TotalTime    time.Duration     `json:"total_time"`
	WebhookID    int64             `json:"webhook_id"`
	DeliveryUUID string            `json:"delivery_uuid"`
}

DeliveryResult represents the final result of a webhook delivery

type HookEvent

type HookEvent struct {
	PushOnly       bool   `json:"push_only"`
	SendEverything bool   `json:"send_everything"`
	ChooseEvents   bool   `json:"choose_events"`
	BranchFilter   string `json:"branch_filter"`

	HookEvents `json:"events"`
}

HookEvent represents events that will delivery hook.

type HookEventType

type HookEventType string

HookEventType is the type of a hook event

const (
	HookEventCreate                    HookEventType = "create"
	HookEventDelete                    HookEventType = "delete"
	HookEventFork                      HookEventType = "fork"
	HookEventPush                      HookEventType = "push"
	HookEventIssues                    HookEventType = "issues"
	HookEventIssueAssign               HookEventType = "issue_assign"
	HookEventIssueLabel                HookEventType = "issue_label"
	HookEventIssueMilestone            HookEventType = "issue_milestone"
	HookEventIssueComment              HookEventType = "issue_comment"
	HookEventPullRequest               HookEventType = "pull_request"
	HookEventPullRequestAssign         HookEventType = "pull_request_assign"
	HookEventPullRequestLabel          HookEventType = "pull_request_label"
	HookEventPullRequestMilestone      HookEventType = "pull_request_milestone"
	HookEventPullRequestComment        HookEventType = "pull_request_comment"
	HookEventPullRequestReviewApproved HookEventType = "pull_request_review_approved"
	HookEventPullRequestReviewRejected HookEventType = "pull_request_review_rejected"
	HookEventPullRequestReviewComment  HookEventType = "pull_request_review_comment"
	HookEventPullRequestSync           HookEventType = "pull_request_sync"
	HookEventPullRequestReviewRequest  HookEventType = "pull_request_review_request"
	HookEventWiki                      HookEventType = "wiki"
	HookEventRepository                HookEventType = "repository"
	HookEventRelease                   HookEventType = "release"
	HookEventPackage                   HookEventType = "package"
	HookEventStatus                    HookEventType = "status"

	// FIXME: This event should be a group of pull_request_review_xxx events
	HookEventPullRequestReview HookEventType = "pull_request_review"
	// Actions event only
	HookEventSchedule    HookEventType = "schedule"
	HookEventWorkflowRun HookEventType = "workflow_run"
	HookEventWorkflowJob HookEventType = "workflow_job"
)

Types of hook events

func AllEvents

func AllEvents() []HookEventType

func (HookEventType) Event

func (h HookEventType) Event() string

Event returns the HookEventType as an event string

func (HookEventType) IsPullRequest

func (h HookEventType) IsPullRequest() bool

type HookEvents

type HookEvents map[HookEventType]bool

func (HookEvents) Get

func (he HookEvents) Get(evt HookEventType) bool

type HookStatus

type HookStatus int

HookStatus is the status of a web hook

const (
	HookStatusNone HookStatus = iota
	HookStatusSucceed
	HookStatusFail
)

Possible statuses of a web hook

type HookType

type HookType = string

HookType is the type of a webhook

const (
	GITEA      HookType = "gitea"
	GOGS       HookType = "gogs"
	SLACK      HookType = "slack"
	DISCORD    HookType = "discord"
	DINGTALK   HookType = "dingtalk"
	TELEGRAM   HookType = "telegram"
	MSTEAMS    HookType = "msteams"
	FEISHU     HookType = "feishu"
	MATRIX     HookType = "matrix"
	WECHATWORK HookType = "wechatwork"
	PACKAGIST  HookType = "packagist"
)

Types of webhooks

type RetryConfig

type RetryConfig struct {
	// MaxRetries is the maximum number of retry attempts
	MaxRetries int

	// InitialDelay is the delay before the first retry
	InitialDelay time.Duration

	// MaxDelay is the maximum delay between retries
	MaxDelay time.Duration

	// Multiplier is the factor by which delay increases
	Multiplier float64

	// Jitter adds randomness to delays (0-1)
	Jitter float64

	// RetryableStatusCodes are HTTP status codes that should trigger a retry
	RetryableStatusCodes []int
}

RetryConfig configures retry behavior

func DefaultRetryConfig

func DefaultRetryConfig() RetryConfig

DefaultRetryConfig returns the default retry configuration

type RetryQueue

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

RetryQueue manages webhook delivery retries

func NewRetryQueue

func NewRetryQueue(config RetryConfig, deliverFunc func(ctx context.Context, d *pendingDelivery) (int, error)) *RetryQueue

NewRetryQueue creates a new retry queue

func (*RetryQueue) Enqueue

func (q *RetryQueue) Enqueue(id string, webhookID int64, url string, payload []byte, headers map[string]string) <-chan *DeliveryResult

Enqueue adds a delivery to the retry queue

func (*RetryQueue) GetStats

func (q *RetryQueue) GetStats() Stats

GetStats returns statistics about the retry queue

func (*RetryQueue) GetStatus

func (q *RetryQueue) GetStatus(id string) (*DeliveryResult, bool)

GetStatus returns the status of a pending delivery

func (*RetryQueue) Stop

func (q *RetryQueue) Stop()

Stop stops the retry queue

type Stats

type Stats struct {
	PendingDeliveries int       `json:"pending_deliveries"`
	TotalRetries      int       `json:"total_retries"`
	SuccessRate       float64   `json:"success_rate"`
	LastUpdated       time.Time `json:"last_updated"`
}

Stats represents retry queue statistics

Source Files

  • events.go
  • retry.go
  • type.go

Jump to

Keyboard shortcuts

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