hooks

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: Apache-2.0 Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const MaxResponseBytes = 1024 * 1024

Variables

This section is empty.

Functions

func HTTPClient

func HTTPClient(base *http.Client, timeoutSec int, blockPrivate bool) *http.Client

HTTPClient bounds delivery time and disables redirects. Private-destination enforcement resolves and dials the same addresses, preventing DNS rebinding.

func SafeURL

func SafeURL(raw string) string

SafeURL excludes query strings and credentials from delivery logs.

func SignRequest

func SignRequest(req *http.Request, body []byte, secret string)

SignRequest authenticates the exact raw body and timestamp. Empty secrets produce no authentication headers; configured headers cannot impersonate one.

func ValidateURL

func ValidateURL(ctx context.Context, raw string, blockPrivate bool) error

ValidateURL only permits absolute HTTP(S) destinations without credentials.

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.

type HookType

type HookType string
const (
	PreTransaction  HookType = "PRE_TRANSACTION"
	PostTransaction HookType = "POST_TRANSACTION"
)

Jump to

Keyboard shortcuts

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