config.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package webhook
  2. import "time"
  3. // Config represents the configuration for a webhook client
  4. type Config struct {
  5. // BaseURL is the base URL for the webhook endpoint
  6. BaseURL string `json:"base_url" validate:"required,url"`
  7. // Domain identifies the source domain sending webhooks
  8. Domain string `json:"domain" validate:"required"`
  9. // SecretKey is used to sign webhook payloads
  10. SecretKey string `json:"secret_key" validate:"required"`
  11. // Timeout is the HTTP client timeout (default: 10s)
  12. Timeout time.Duration `json:"timeout"`
  13. // MaxRetries is the maximum number of retry attempts (default: 3)
  14. MaxRetries int `json:"max_retries"`
  15. // RetryBackoff is the duration to wait between retries (default: 1s)
  16. RetryBackoff time.Duration `json:"retry_backoff"`
  17. }
  18. // DefaultConfig returns a Config with default values
  19. func DefaultConfig() Config {
  20. return Config{
  21. Timeout: 10 * time.Second,
  22. MaxRetries: 3,
  23. RetryBackoff: time.Second,
  24. }
  25. }
  26. // Validate checks the configuration for required fields
  27. func (c *Config) Validate() error {
  28. if c.BaseURL == "" || c.Domain == "" || c.SecretKey == "" {
  29. return ErrInvalidConfig
  30. }
  31. return nil
  32. }