1234567891011121314151617181920212223242526272829303132333435363738394041 |
- package webhook
- import "time"
- // Config represents the configuration for a webhook client
- type Config struct {
- // BaseURL is the base URL for the webhook endpoint
- BaseURL string `json:"base_url" validate:"required,url"`
- // Domain identifies the source domain sending webhooks
- Domain string `json:"domain" validate:"required"`
- // SecretKey is used to sign webhook payloads
- SecretKey string `json:"secret_key" validate:"required"`
- // Timeout is the HTTP client timeout (default: 10s)
- Timeout time.Duration `json:"timeout"`
- // MaxRetries is the maximum number of retry attempts (default: 3)
- MaxRetries int `json:"max_retries"`
- // RetryBackoff is the duration to wait between retries (default: 1s)
- RetryBackoff time.Duration `json:"retry_backoff"`
- }
- // DefaultConfig returns a Config with default values
- func DefaultConfig() Config {
- return Config{
- Timeout: 10 * time.Second,
- MaxRetries: 3,
- RetryBackoff: time.Second,
- }
- }
- // Validate checks the configuration for required fields
- func (c *Config) Validate() error {
- if c.BaseURL == "" || c.Domain == "" || c.SecretKey == "" {
- return ErrInvalidConfig
- }
- return nil
- }
|