Documentation
¶
Index ¶
- Constants
- func HTTPClient(base *http.Client, timeoutSec int, blockPrivate bool) *http.Client
- func SafeURL(raw string) string
- func SignRequest(req *http.Request, body []byte, secret string)
- func ValidateURL(ctx context.Context, raw string, blockPrivate bool) error
- type Hook
- type HookManager
- type HookPayload
- type HookResponse
- type HookTaskPayload
- type HookType
Constants ¶
const MaxResponseBytes = 1024 * 1024
Variables ¶
This section is empty.
Functions ¶
func HTTPClient ¶
HTTPClient bounds delivery time and disables redirects. Private-destination enforcement resolves and dials the same addresses, preventing DNS rebinding.
func SignRequest ¶
SignRequest authenticates the exact raw body and timestamp. Empty secrets produce no authentication headers; configured headers cannot impersonate one.
Types ¶
type Hook ¶
type Hook struct {
ID string `json:"id"` // Unique identifier for the hook
Name string `json:"name"` // Friendly name for the hook
URL string `json:"url"` // Webhook endpoint URL
Type HookType `json:"type"` // Type of hook (pre or post transaction)
Active bool `json:"active"` // Whether the hook is currently active
Timeout int `json:"timeout"` // Timeout in seconds for the webhook call
RetryCount int `json:"retry_count"` // Number of retries on failure
CreatedAt time.Time `json:"created_at"` // Creation timestamp
LastRun time.Time `json:"last_run"` // Last execution timestamp
LastSuccess bool `json:"last_success"` // Status of last execution
}
Hook represents a webhook configuration.
type HookManager ¶
type HookManager interface {
RegisterHook(ctx context.Context, hook *Hook) error
UpdateHook(ctx context.Context, hookID string, hook *Hook) error
DeleteHook(ctx context.Context, hookID string) error
GetHook(ctx context.Context, hookID string) (*Hook, error)
ListHooks(ctx context.Context, hookType HookType) ([]*Hook, error)
ExecuteHooks(ctx context.Context, hooks []*Hook, hookType HookType, transactionID string, data interface{}) error
ExecutePreHooks(ctx context.Context, transactionID string, data interface{}) error
ExecutePostHooks(ctx context.Context, transactionID string, data interface{}) error
ProcessHookTask(ctx context.Context, task *asynq.Task) error
}
HookManager defines the interface for managing hooks.
func NewHookManager ¶
func NewHookManager(redisClient redis.UniversalClient, queue *asynq.Client) HookManager
NewHookManager creates a new Redis-based hook manager. It initializes the hook manager with the provided Redis client and Asynq client.
Parameters: - redisClient: The Redis client for storing hook configurations. - queue: The Asynq client for queuing hook execution tasks.
Returns: - HookManager: A new instance of the hook manager.
type HookPayload ¶
type HookPayload struct {
TransactionID string `json:"transaction_id"`
HookType HookType `json:"hook_type"`
Timestamp time.Time `json:"timestamp"`
Data json.RawMessage `json:"data,omitempty"` // Changed to omitempty to handle nil data
}
HookPayload represents the data sent to webhook endpoints.
type HookResponse ¶
type HookResponse struct {
Success bool `json:"success"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
}
HookResponse represents the expected response from webhook endpoints.
type HookTaskPayload ¶
type HookTaskPayload struct {
Hook *Hook `json:"hook"`
Payload HookPayload `json:"payload"`
TransactionID string `json:"transaction_id"`
Data interface{} `json:"data"`
Transaction *model.Transaction `json:"transaction"`
}
HookTaskPayload represents the payload for a queued hook task.