webhook

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2025 License: MIT Imports: 7 Imported by: 0

README

WebHook

Documentation

Index

Constants

View Source
const (
	APP_NAME = "webhooks"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type QueryWebHookRequest

type QueryWebHookRequest struct {
	// 关联Task
	RefTaskId string `json:"ref_task_id"`
}

func NewQueryWebHookRequest

func NewQueryWebHookRequest() *QueryWebHookRequest

func (*QueryWebHookRequest) SetRefTaskId

func (r *QueryWebHookRequest) SetRefTaskId(taskId string) *QueryWebHookRequest

type STATUS

type STATUS int
const (
	// 任务处于挂起
	STATUS_PENDING STATUS = iota
	// 任务正在运行
	STATUS_RUNNING
	// 任务已完成
	STATUS_SUCCESS
	// 任务失败
	STATUS_FAILED
	// 任务已取消
	STATUS_CANCELED
)

type Service

type Service interface {
	// 执行WebHook
	Run(context.Context, *WebHookSpec) *WebHook
	// 查询WebHook执行记录
	QueryWebHook(context.Context, *QueryWebHookRequest) (*types.Set[*WebHook], error)
}

func GetService

func GetService() Service

type WebHook

type WebHook struct {
	// WebHook 的唯一标识
	ID string `json:"id"`
	// 创建时间
	CreatedAt time.Time `` /* 126-byte string literal not displayed */
	// WebHook定义
	WebHookSpec
	// 状态与统计
	WebHookStatus
}

任务回调

func NewWebHook

func NewWebHook(spec WebHookSpec) *WebHook

func (*WebHook) Failed

func (w *WebHook) Failed(err error) *WebHook

func (*WebHook) Run

func (h *WebHook) Run(ctx context.Context)

func (*WebHook) SetDefault

func (h *WebHook) SetDefault()

func (*WebHook) Success

func (w *WebHook) Success() *WebHook

func (*WebHook) TableName

func (h *WebHook) TableName() string

type WebHookSpec

type WebHookSpec struct {
	// WebHook 名称
	Name string `json:"name"`
	// 描述
	Description string `json:"description"`

	// 关联Task
	RefTaskId string `json:"ref_task_id"`

	// 目标配置
	// 接收 HTTP 请求的 URL
	TargetURL string `json:"target_url"`
	// HTTP 方法,如 POST、GET 等
	Method string `json:"method"`
	// 自定义请求头
	Headers map[string]string `json:"headers" gorm:"column:headers;type:json;serializer:json;"`

	// 安全验证
	// 用于签名验证的密钥(HMAC)
	Secret string `json:"secret"`
	// 签名头的名称,如 "X-Hub-Signature"
	SignatureHeader string `json:"signature_header"`

	// 哪些条件下触发
	Conditions []string `json:"conditions" gorm:"column:conditions;type:json;serializer:json;"`

	// 请求内容配置
	// 请求体类型,如 "application/json"
	ContentType string `json:"content_type"`
	// 自定义请求体模板(可选)
	Payload string `json:"payload"`

	// 重试与超时
	// 失败重试次数
	RetryCount int `json:"retry_count"`
	// 请求超时时间(毫秒)
	Timeout int `json:"timeout"`
}

func (*WebHookSpec) AddCondtion

func (s *WebHookSpec) AddCondtion(conditions ...string)

func (*WebHookSpec) IsCondtionOk

func (s *WebHookSpec) IsCondtionOk(condition string) bool

type WebHookStatus

type WebHookStatus struct {
	// 状态与统计
	Status STATUS `json:"status"`
	// 失败信息
	Message string `json:"message"`
}

func NewWebHookStatus

func NewWebHookStatus() *WebHookStatus

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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