Documentation ¶
Index ¶
- func AddWebhookConfig(c *gin.Context)
- func CreateCondition(c *gin.Context)
- func DalAddWebhookConfig(req *AddWebhookConfigRequest) (*model.WebHook, *model.WebHookCondition, []model.NeedNode)
- func DalCreateCondition(req *CreateConditionRequest) *model.WebHookCondition
- func DalDeleteCondition(id int64)
- func DalGetAllConditionsByPage(page int, pageSize int) ([]*model.WebHookCondition, int64, error)
- func DalGetConditionById(id int64) *model.WebHookCondition
- func DalGetNeedNodesByWebhookId(id int64) []*model.NeedNode
- func DalGetWebhookConfigById(id int64) (*model.WebHook, *model.WebHookCondition)
- func DalGetWebhookConfigByName(name string) *model.WebHook
- func DalUpdateCondition(id int64, req *UpdateConditionRequest) *model.WebHookCondition
- func DeleteCondition(c *gin.Context)
- func GetAllConditionsByPage(c *gin.Context)
- func GetConditionById(c *gin.Context)
- func GetNeedeNodesListByWebhookId(id int64) []string
- func GetWebhookConfigById(c *gin.Context)
- func GetWebhookConfigByName(c *gin.Context)
- func RegisterRoutes(router *gin.RouterGroup)
- func ServiceDeleteCondition(id string)
- func UpdateCondition(c *gin.Context)
- func WebHookExample(c *gin.Context)
- type AddWebhookConfigRequest
- type AddWebhookConfigResponse
- type CreateConditionRequest
- type CreateConditionResponse
- type DeleteConditionResponse
- type GetAllConditionsByPageData
- type GetAllConditionsByPageRequest
- type GetAllConditionsByPageResponse
- type GetConditionByIdResponse
- type GetWebhookConfigByIdResponse
- type GetWebhookConfigByNameRequest
- type GetWebhookConfigByNameResponse
- type UpdateConditionRequest
- type UpdateConditionResponse
- type WebHookConditionRead
- func ServiceCreateCondition(req *CreateConditionRequest) WebHookConditionRead
- func ServiceGetAllConditionsByPage(req GetAllConditionsByPageRequest) ([]WebHookConditionRead, int64)
- func ServiceGetConditionById(id string) WebHookConditionRead
- func ServiceUpdateCondition(id string, req *UpdateConditionRequest) WebHookConditionRead
- type WebHookConfigRead
- type WebHookExampleRequest
- type WebHookExampleResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddWebhookConfig ¶
AddWebhookConfig router ------------------------------------- @Summary 配置一条新的webhook 步骤**2** @Description # 配置一条新的webhook @Description ## 说明 @Description 该接口用于配置一条新的webhook,并通过when字段或condition_id字段配置触发条件,当条件满足时会触发webhook,并将所需要的数据传给webhook url接口。 @Description ## 请求参数 @Description @Description - name:webhook名称,为空时系统会自动生成一个uuid @Description - url:webhook地址(POST请求),必填,当条件满足时会调用该url,并挂载数据到body中 @Description - active:是否激活,不传的话默认true @Description - when:条件,里面是一个json,具体的格式看/api/v1/webhook/condition接口说明,when其实就是一个condition条件。该字段和condition_id字段必须传一个。 @Description - condition_id:条件id,将条件condition配置到webhook上,该字段和when字段必须传一个。 @Description - need_node_list:需要的节点值列表,条件触发时会传参给webhook @Description ## 例1:当节点node1值等于123时,发送通知到http://localhost:8080/api/v1/webhook/example @Description ```json @Description { @Description "active": true, @Description "name":"webhook1", @Description "url": "http://localhost:8080/api/v1/webhook/example", @Description "when": { @Description "rule": { @Description "node_name": "node1", @Description "type": "eq", @Description "value": 123 @Description } @Description } @Description } @Description ``` @Description 使用when字段会创建新的条件condition,并将其配置在这个webhook上 @Description ## 例2:使用已经配置好的条件condition @Description ```json @Description { @Description "active": true, @Description "url": "http://localhost:8080/api/v1/webhook/example", @Description "condition_id": 10 @Description } @Description ``` @Description ## 常见异常 @Description - "code": 2007 代表数据重复,不能创建重复的webhook,具体重复了哪个字段,请看ConstraintName最后一个下划线后面的字段名 @Description - "code": 400 "json: cannot unmarshal string into Go struct field AddWebhookConfigRequest.condition_id of type int64" : 看下body参数,数字类型传成了字符串 @Tags Webhook @Accept json @Produce json @Param body body AddWebhookConfigRequest true "Webhook configuration" @Success 200 {object} AddWebhookConfigResponse @Router /api/v1/webhook [post]
func CreateCondition ¶
CreateCondition router ------------------------------------- @Summary 创建触发条件 @Description # 参数说明 @Description ## 请求参数 @Description | 参数名称 | 类型 | 必填 | 描述 | @Description | --- | --- | --- | --- | @Description | and | list中嵌套本参数 | 否 | 规则列表,逻辑与 | @Description | or | list中嵌套本参数 | 否 | 规则列表,逻辑或 | @Description | rule | Rule | 否 | 规则 | @Description ## Rule类型 定义 @Description | 字段 | 类型 | 必填 | 描述 | @Description | --- | --- | --- | --- | @Description | node_name | string | 是 | 节点名称 | @Description | type | string | 是 | 规则类型,支持eq ne gt lt all-time in not-in | @Description | value | any | 是 | 比对值 | @Description ## 参数示例1 : 当节点MyVariable大于123时触发 @Description ```json @Description { @Description "rule": { @Description "node_name": "MyVariable", @Description "type": "gt", @Description "value": 123 @Description } @Description } @Description ``` @Description ## 参数示例2 : 当节点node1等于在["abc","def"],并且节点node2等于123时触发 @Description ```json @Description { @Description "and": [ @Description { @Description "rule": { @Description "node_name": "node1", @Description "type": "in", @Description "value": [ @Description "abc", @Description "def" @Description ] @Description } @Description }, @Description { @Description "rule": { @Description "node_name": "node2", @Description "type": "eq", @Description "value": 123 @Description } @Description } @Description ] @Description } @Description ``` @Description ## 参数示例3 : 一直触发 @Description ```json @Description { @Description "rule": { @Description "type": "all-time" @Description } @Description } @Description ``` @Description *注意:Condition是嵌套类型,Condition包含and,or,rule,所以and里面可以嵌套and。。。无限嵌套* @Tags Webhook @Accept json @Produce json @Param body body CreateConditionRequest true "创建条件" @Success 200 {object} CreateConditionResponse @Router /api/v1/webhook/condition [post]
func DalAddWebhookConfig ¶
func DalAddWebhookConfig(req *AddWebhookConfigRequest) (*model.WebHook, *model.WebHookCondition, []model.NeedNode)
{"name":"webhook1","url":"http://localhost:8080/api/v1/webhook/example","active":true,"when":{"and":null,"or":null,"rule":{"type":"eq","node_name":"node1","value":"123"}},"condition_id":null} {"name":"webhook1","url":"http://localhost:8080/api/v1/webhook/example","active":true,"when":{"and":null,"or":null,"rule":{"type":"eq","node_name":"node1","value":"123"}},"condition_id":null}
func DalCreateCondition ¶
func DalCreateCondition(req *CreateConditionRequest) *model.WebHookCondition
func DalDeleteCondition ¶
func DalDeleteCondition(id int64)
func DalGetConditionById ¶
func DalGetConditionById(id int64) *model.WebHookCondition
func DalGetWebhookConfigById ¶
func DalGetWebhookConfigById(id int64) (*model.WebHook, *model.WebHookCondition)
func DalUpdateCondition ¶
func DalUpdateCondition(id int64, req *UpdateConditionRequest) *model.WebHookCondition
func DeleteCondition ¶
DeleteCondition router - @Summary 删除触发条件 @Tags Webhook @Accept json @Produce json @Param id path int true "条件ID" @Success 200 {object} DeleteConditionResponse @Router /api/v1/webhook/condition/{id} [delete]
func GetAllConditionsByPage ¶
GetAllConditionsByPage router - @Summary 获取触发条件列表 @Description # 参数说明 @Description ## 请求参数 @Description | 参数名称 | 类型 | 必填 | 描述 | @Description | --- | --- | --- | --- | @Description | page | int | 是 | 页码 | @Description | page_size | int | 是 | 每页数量 | @Description ## 返回参数 @Description | 参数名称 | 类型 | 描述 | @Description | --- | --- | --- | @Description | id | int | 条件ID | @Description | condition | string | 条件表达式 | @Description | created_at | time.Time | 创建时间 | @Description | updated_at | time.Time | 更新时间 | @Tags Webhook @Accept json @Produce json @Param name query GetAllConditionsByPageRequest true "获取条件列表" @Success 200 {object} GetAllConditionsByPageResponse @Router /api/v1/webhook/conditions [get]
func GetConditionById ¶
func GetWebhookConfigById ¶
GetWebhookConfigById router ------------------------------- @Summary 根据id获取webhook配置 @Description 根据id获取webhook配置 @Tags Webhook @Accept json @Produce json @Param id path string true "webhook id" @Success 200 {object} GetWebhookConfigByIdResponse @Router /api/v1/webhook/{id} [get]
func GetWebhookConfigByName ¶
GetWebhookConfigByName router ------------------------------ @Summary 根据名称获取webhook配置 @Description 根据名称获取webhook配置 @Tags Webhook @Accept json @Produce json @Param name query GetWebhookConfigByNameRequest true "webhook名称" @Success 200 {object} GetWebhookConfigByNameResponse @Router /api/v1/webhook [get]
func RegisterRoutes ¶
func RegisterRoutes(router *gin.RouterGroup)
func ServiceDeleteCondition ¶
func ServiceDeleteCondition(id string)
func UpdateCondition ¶
UpdateCondition router - @Summary 更新触发条件 @Description # 参数说明 @Description ## 请求参数 @Description | 参数名称 | 类型 | 必填 | 描述 | @Description | --- | --- | --- | --- | @Description | id | int | 是 | 条件ID | @Description | and | list中嵌套本参数 | 否 | 规则列表,逻辑与 | @Description | or | list中嵌套本参数 | 否 | 规则列表,逻辑或 | @Description | rule | Rule | 否 | 规则 | @Description ## Rule类型 定义 @Description | 字段 | 类型 | 是否必填 | 描述 | @Description | --- | --- | --- | --- | @Description | node_name | string | 是 | 节点名称 | @Description | type | string | 是 | 规则类型,支持eq ne gt lt all-time in not-in | @Description | value | any | 是 | 比对值 | @Description ## 参数示例1 : 更新条件ID为1的条件,将节点MyVariable大于123改为小于123 @Description ```json @Description { @Description "id": 1, @Description "rule": { @Description "node_name": "MyVariable", @Description "type": "lt", @Description "value": 123 @Description } @Description } @Description ``` @Description ## 参数示例2 : 更新条件ID为2的条件,将节点node1等于在["abc","def"],并且节点node2等于123改为节点node1等于在["abc","def"],并且节点node2等于123 @Description ```json @Description { @Description "id": 2, @Description "and": [ @Description { @Description "rule": { @Description "node_name": "node1", @Description "type": "in", @Description "value": [ @Description "abc", @Description "def" @Description ] @Description } @Description }, @Description { @Description "rule": { @Description "node_name": "node2", @Description "type": "eq", @Description "value": 123 @Description } @Description } @Description ] @Description } @Description ``` @Description ## 参数示例3 : 更新条件ID为3的条件,将一直触发改为节点node1等于123 @Description ```json @Description { @Description "id": 3, @Description "rule": { @Description "node_name": "node1", @Description "type": "eq", @Description "value": 123 @Description } @Description } @Description ``` @Description *注意:Condition是嵌套类型,Condition包含and,or,rule,所以and里面可以嵌套and。。。无限嵌套* @Tags Webhook @Accept json @Produce json @Param id path int true "条件ID" @Param body body UpdateConditionRequest true "更新条件" @Success 200 {object} UpdateConditionResponse @Router /api/v1/webhook/condition/{id} [put]
func WebHookExample ¶
WebHookExample router --------------------------------------- @Summary webhook示例 要像这个接口一样去定义参数,带两个字段,一个是values,一个是timestamp。注意,必须是post请求。 @Description webhook示例 @Tags Webhook Example @Accept json @Produce json @Param body body WebHookExampleRequest true "Webhook example" @Success 200 {object} WebHookExampleResponse @Router /api/v1/webhook/example [POST]
Types ¶
type AddWebhookConfigRequest ¶
type AddWebhookConfigRequest struct { Name *string `json:"name" form:"name" example:"webhook1"` // webhook名称,可以为空 Url string `json:"url" form:"url" binding:"required,url" example:"http://192.168.1.1:8800/notify"` // webhook地址 Active *bool `json:"active" form:"active" example:"true"` // 是否激活,不传的话默认true When *globaldata.Condition `json:"when" form:"when"` // 触发条件,为空时相当于通知所有数据变化 ConditionId *int64 `json:"condition_id" form:"condition_id" example:"1"` // 条件id,不传的话默认新增条件 NeedNodeList []string `json:"need_node_list" form:"need_node_list" binding:"required"` // 需要的节点值列表,到时候会传参给webhook } // Todo: NeedNodeList 解除required限制,因为有时候不需要汇报数据
GetWebhookConfig router 参数定义,字段描述放在字段后面
type AddWebhookConfigResponse ¶
type AddWebhookConfigResponse struct { Code int `json:"code" example:"200"` Data WebHookConfigRead `json:"data"` Message string `json:"message" example:"节点添加成功"` }
type CreateConditionRequest ¶
type CreateConditionRequest struct { And []globaldata.Condition `json:"and" form:"and"` // 规则列表,逻辑与 Or []globaldata.Condition `json:"or" form:"or"` // 规则列表,逻辑或 Rule *globaldata.Rule `json:"rule" form:"rule"` // 规则 }
type CreateConditionResponse ¶
type CreateConditionResponse struct { Code int `json:"code" example:"200"` Data WebHookConditionRead `json:"data" ` Message string `json:"message" example:"Condition created successfully"` }
type DeleteConditionResponse ¶
type GetAllConditionsByPageData ¶
type GetAllConditionsByPageData struct { Conditions []WebHookConditionRead `json:"conditions" form:"conditions" validate:"required"` Total int64 `json:"total" form:"total" validate:"required"` }
type GetAllConditionsByPageResponse ¶
type GetAllConditionsByPageResponse struct { Code int `json:"code" example:"200"` Data GetAllConditionsByPageData `json:"data" ` Message string `json:"message" example:"Condition get successfully"` }
type GetConditionByIdResponse ¶
type GetConditionByIdResponse struct { Code int `json:"code" example:"200"` Data WebHookConditionRead `json:"data" ` Message string `json:"message" example:"Condition get successfully"` }
type GetWebhookConfigByIdResponse ¶
type GetWebhookConfigByIdResponse struct { Code int `json:"code" example:"200"` Data WebHookConfigRead `json:"data" ` Message string `json:"message" example:"Webhook configuration get successfully"` }
type GetWebhookConfigByNameRequest ¶
type GetWebhookConfigByNameRequest struct {
Name string `json:"name" form:"name" example:"webhook1"` // webhook名称
}
type GetWebhookConfigByNameResponse ¶
type GetWebhookConfigByNameResponse struct { Code int `json:"code" example:"200"` Data WebHookConfigRead `json:"data" ` Message string `json:"message" example:"Webhook configuration get successfully"` }
type UpdateConditionRequest ¶
type UpdateConditionRequest struct { And []globaldata.Condition `json:"and" form:"and"` // 规则列表,逻辑与 Or []globaldata.Condition `json:"or" form:"or"` // 规则列表,逻辑或 Rule *globaldata.Rule `json:"rule" form:"rule"` // 规则 }
type UpdateConditionResponse ¶
type UpdateConditionResponse struct { Code int `json:"code" example:"200"` Data WebHookConditionRead `json:"data" ` Message string `json:"message" example:"Condition updated successfully"` }
type WebHookConditionRead ¶
type WebHookConditionRead struct { Id int64 `json:"id" form:"id" validate:"required"` Condition string `json:"condition" form:"condition" validate:"required"` CreatedAt time.Time `json:"created_at" form:"created_at" validate:"required"` UpdatedAt time.Time `json:"updated_at" form:"updated_at" validate:"required"` }
func ServiceCreateCondition ¶
func ServiceCreateCondition(req *CreateConditionRequest) WebHookConditionRead
func ServiceGetAllConditionsByPage ¶
func ServiceGetAllConditionsByPage(req GetAllConditionsByPageRequest) ([]WebHookConditionRead, int64)
func ServiceGetConditionById ¶
func ServiceGetConditionById(id string) WebHookConditionRead
func ServiceUpdateCondition ¶
func ServiceUpdateCondition(id string, req *UpdateConditionRequest) WebHookConditionRead
type WebHookConfigRead ¶
type WebHookConfigRead struct { Id int64 `json:"id" form:"id" validate:"required"` Name string `json:"name" form:"name" validate:"required"` Url string `json:"url" form:"url" validate:"required"` Active bool `json:"active" form:"active" validate:"required"` When *string `json:"when" form:"when" validate:"omitempty"` NeedNodeList []string `validate:"required"` ConditionId *int64 `json:"condition_id" form:"condition_id" validate:"omitempty"` CreatedAt time.Time `json:"created_at" form:"created_at" validate:"required"` UpdatedAt time.Time `json:"updated_at" form:"updated_at" validate:"required"` }
func GetAllWebhookConfigFromDB ¶
func GetAllWebhookConfigFromDB() []WebHookConfigRead
func GetWebhookConfigByIdFromDB ¶
func GetWebhookConfigByIdFromDB(id int64) WebHookConfigRead
func ServiceAddWebhookConfig ¶
func ServiceAddWebhookConfig(req *AddWebhookConfigRequest) WebHookConfigRead
func ServiceGetWebhookConfigById ¶
func ServiceGetWebhookConfigById(id string) WebHookConfigRead