webhook

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2025 License: MIT Imports: 10 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 DescribeWebHookRequest added in v0.0.21

type DescribeWebHookRequest struct {
	Id string
}

func NewDescribeWebHookRequest added in v0.0.21

func NewDescribeWebHookRequest(id string) *DescribeWebHookRequest

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, 触发执行, 执行状态通过HookId查询
	Run(context.Context, *WebHookSpec) (*WebHook, error)
	// 查询WebHook具体执行状态
	DescribeWebHook(context.Context, *DescribeWebHookRequest) (*WebHook, error)
	// 查询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) LoadFromEvent added in v0.0.21

func (e *WebHook) LoadFromEvent(event *bus.Event) error

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

func (*WebHook) ToBusEvent added in v0.0.21

func (e *WebHook) ToBusEvent(topic string) *bus.Event

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 NewWebHookSpec added in v0.0.21

func NewWebHookSpec() *WebHookSpec

func (*WebHookSpec) AddCondtion

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

func (*WebHookSpec) IsCondtionOk

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

type WebHookStatus

type WebHookStatus struct {
	// 更新时间
	UpdateAt *time.Time `json:"update_at" gorm:"column:update_at;type:timestamp;default:current_timestamp;not null;index;" description:"更新时间"`
	// 状态与统计
	Status STATUS `json:"status" gorm:"column:status;type:varchar(32);not null;" description:"状态"`
	// 失败信息
	Message string `json:"message" gorm:"column:message;type:text;" description:"失败信息"`
}

func NewWebHookStatus

func NewWebHookStatus() *WebHookStatus

func (*WebHookStatus) SetUpdateAt added in v0.0.21

func (w *WebHookStatus) SetUpdateAt(v time.Time) *WebHookStatus

func (WebHookStatus) String added in v0.0.21

func (w WebHookStatus) String() string

func (WebHookStatus) TableName added in v0.0.21

func (w WebHookStatus) TableName() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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