Documentation
¶
Index ¶
- Constants
- Variables
- func GetDeliveryID(req *http.Request) string
- func GetEventType(req *http.Request) string
- func VerifyPayload(payload []byte, signature string, secret string) error
- func VerifyRequest(req *http.Request, payload []byte, secret string) error
- func VerifySignature(payload []byte, signature string, secret string) bool
- type Delivery
- type DeliveryConfig
- type DeliveryService
Constants ¶
View Source
const SignatureHeaderName = "X-Webhook-Signature"
SignatureHeaderName is the header used for webhook signatures.
Variables ¶
View Source
var ( ErrInvalidSignature = errors.New("invalid webhook signature") ErrMissingSignature = errors.New("missing webhook signature header") )
Signature verification errors.
Functions ¶
func GetDeliveryID ¶
GetDeliveryID extracts the delivery ID from the request header.
func GetEventType ¶
GetEventType extracts the event type from the request header.
func VerifyPayload ¶
VerifyPayload verifies a raw payload against a signature.
func VerifyRequest ¶
VerifyRequest verifies the signature of an incoming webhook request.
Types ¶
type Delivery ¶
type Delivery struct {
ID string `json:"id"`
EventType string `json:"event_type"`
URL string `json:"url"`
Payload json.RawMessage `json:"payload"`
Headers http.Header `json:"headers"`
StatusCode int `json:"status_code"`
Response string `json:"response,omitempty"`
Duration time.Duration `json:"duration"`
Success bool `json:"success"`
Retries int `json:"retries"`
CreatedAt time.Time `json:"created_at"`
SentAt *time.Time `json:"sent_at,omitempty"`
}
Delivery represents a webhook delivery attempt.
type DeliveryConfig ¶
type DeliveryConfig struct {
Timeout time.Duration `default:"30s"`
MaxRetries int `default:"5"`
RetryBackoff time.Duration `default:"1s"`
SignAlgorithm string `default:"hmac-sha256"`
}
DeliveryConfig holds configuration for webhook delivery.
type DeliveryService ¶
type DeliveryService struct {
// contains filtered or unexported fields
}
DeliveryService handles webhook deliveries.
func NewDeliveryService ¶
func NewDeliveryService(secret string, config DeliveryConfig, logger *slog.Logger) *DeliveryService
NewDeliveryService creates a new webhook delivery service.
Click to show internal directories.
Click to hide internal directories.