hooks

package module
v0.0.0-...-74031c7 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2025 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteHook

func DeleteHook(db *gorm.DB, hookID int64) error

Types

type Hook

type Hook struct {
	Name        string          `json:"name,omitempty"`
	Trigger     HookTrigger     `json:"trigger,omitempty"`
	Action      HookAction      `json:"action,omitempty"`
	ProcessType HookProcessType `json:"process_type,omitempty"`
	Type        HookType        `json:"type,omitempty"`
}

func FilterHooksByType

func FilterHooksByType(allHooks []Hook, hookType HookType) []Hook

func GetHooksByTriggerOnAndModel

func GetHooksByTriggerOnAndModel(allHooks []Hook, on HookTriggerOn, model string) []Hook

func (*Hook) Execute

func (s *Hook) Execute(data HookPayload) error

func (*Hook) Run

func (s *Hook) Run(data HookPayload) error

func (*Hook) Scan

func (s *Hook) Scan(value interface{}) error

func (*Hook) Value

func (s *Hook) Value() (driver.Value, error)

type HookAction

type HookAction string
const (
	HookActionWebhook         HookAction = "Webhook"
	HookActionTriggerFunction HookAction = "Internal-Function"
)

type HookConditions

type HookConditions struct {
	Where   map[string]interface{} `json:"where,omitempty"`
	Limit   int64                  `json:"limit,omitempty"`
	Offset  int64                  `json:"offset,omitempty"`
	OrderBy string                 `json:"order_by,omitempty"`
	Set     map[string]interface{} `json:"set,omitempty"`
}

type HookLogsModel

type HookLogsModel struct {
	ID         int64      `gorm:"column:id;primaryKey;autoIncrement" json:"id,omitempty"`
	Details    Hook       `gorm:"column:details;type:jsonb" json:"details,omitempty"`
	ExecutedAt *time.Time `gorm:"column:executed_on;default:CURRENT_TIMESTAMP" json:"executed_at,omitempty"`
}

func (*HookLogsModel) Create

func (t *HookLogsModel) Create(db *gorm.DB) error

func (*HookLogsModel) Get

func (t *HookLogsModel) Get(db *gorm.DB) ([]*HookLogsModel, error)

func (*HookLogsModel) GetByID

func (t *HookLogsModel) GetByID(db *gorm.DB, id int64) (*HookLogsModel, error)

func (*HookLogsModel) TableName

func (t *HookLogsModel) TableName() string

type HookPayload

type HookPayload struct {
	TriggerAction []HookTriggerOn `json:"trigger_action,omitempty"`
	TriggerModels []string        `json:"trigger_models,omitempty"`
	OutputData    OutputData      `json:"output_data,omitempty"`
	Input         HookConditions  `json:"input,omitempty"`
}

type HookProcessType

type HookProcessType string
const (
	HookProcessSync  HookProcessType = "Sync"
	HookProcessAsync HookProcessType = "Async"
)

type HookQuery

type HookQuery struct {
	Sql  string        `json:"sql,omitempty"`
	Args []interface{} `json:"args,omitempty"`
}

type HookTrigger

type HookTrigger struct {
	On       []HookTriggerOn         `json:"on,omitempty"`
	Models   []string                `json:"model,omitempty"`
	Func     func(HookPayload) error `json:"-"`
	Webhooks []WebHook               `json:"webhooks,omitempty"`
}

type HookTriggerOn

type HookTriggerOn string
const (
	HookTriggerOnStartTransaction HookTriggerOn = "Start-Transaction"
	HookTriggerOnCommit           HookTriggerOn = "Commit-Transaction"
	HookTriggerOnRollback         HookTriggerOn = "Rollback-Transaction"
	HookTriggerOnCreate           HookTriggerOn = "Create"
	HookTriggerOnUpdate           HookTriggerOn = "Update"
	HookTriggerOnDelete           HookTriggerOn = "Delete"
)

type HookType

type HookType string
const (
	HookTypePre  HookType = "Pre"
	HookTypePost HookType = "Post"
)

type OutputData

type OutputData struct {
	Count              int64       `json:"count,omitempty"`
	OperationStartedAt *time.Time  `json:"operation_started_at,omitempty"`
	OperationEndedAt   *time.Time  `json:"operation_ended_at,omitempty"`
	Query              HookQuery   `json:"query,omitempty"`
	Result             interface{} `json:"result,omitempty"`
}

type WebHook

type WebHook struct {
	TargetUrl string            `json:"target_url,omitempty"`
	Headers   map[string]string `json:"headers,omitempty"`
	Method    string            `json:"method,omitempty"`
	Timeout   time.Duration     `json:"timeout,omitempty"`
}

func (*WebHook) Run

func (w *WebHook) Run(data HookPayload) error

Jump to

Keyboard shortcuts

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