From 93a855d1aeece35e94b37e741284d96614ce8f0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Fri, 28 Mar 2025 15:10:16 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=84=E5=88=92mesh=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E7=9A=84=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- httpclient/define/mesh.go | 76 +++++++++++++++++++++++++++++++++++++++ httpclient/mesh/mesh.go | 8 +++++ 2 files changed, 84 insertions(+) create mode 100644 httpclient/define/mesh.go create mode 100644 httpclient/mesh/mesh.go diff --git a/httpclient/define/mesh.go b/httpclient/define/mesh.go new file mode 100644 index 0000000..f9c46ac --- /dev/null +++ b/httpclient/define/mesh.go @@ -0,0 +1,76 @@ +// Package define ... +// +// Description : define ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2025-03-28 14:12 +package define + +import ( + "git.zhangdeman.cn/zhangdeman/consts" + "sync" +) + +// MeshRequestConfig 聚合请求 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 14:14 2025/3/28 +type MeshRequestConfig struct { + CommonParam map[string]any `json:"common_param"` // 公共参数 + Group [][]MeshRequestConfigGroupItem `json:"group"` // 请求分组 + ResultRule []MeshRequestConfigResultRule `json:"result_rule"` // 结果提取规则, 多个接口的结果构造成一个返回结果 + Receiver any `json:"-"` // 整体请求结果数据接收的指针 +} + +// MeshRequestConfigGroupItem 分组请求每一项的结构 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 14:16 2025/3/28 +type MeshRequestConfigGroupItem struct { + Alias string `json:"alias"` // 请求别名 + ParamRuleList []MeshRequestConfigGroupItemParamRule `json:"param_rule_list"` // 参数规则列表 + RequestCfg Request `json:"request_cfg"` // 请求配置 + Condition any `json:"condition"` // TODO: 请求条件, 特定条件下不执行当前请求 +} + +// MeshRequestConfigGroupItemParamRule 参数提取规则 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 14:23 2025/3/28 +type MeshRequestConfigGroupItemParamRule struct { + Location consts.RequestDataLocation `json:"location"` // 参数位置 + Path string `json:"path"` // 参数设置的路径 + Type consts.DataType `json:"type"` // 参数类型 + SourceAlias string `json:"source_alias"` // 数据源请求别名 __COMMON__ 代表从公共参数读取数据 + SourceResultPath string `json:"source_result_path"` // 数据源数据, 从结果中获取的路径 +} + +// MeshRequestConfigResultRule 返回值构建规则 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 14:28 2025/3/28 +type MeshRequestConfigResultRule struct { + RequestAlias string `json:"request_alias"` // 请求别名 + RequestResultLocation consts.ResponseDataLocation `json:"request_result_location"` // 请求结果位置 + RequestResultPath string `json:"request_result_path"` // 请求结果路径 + Location consts.ResponseDataLocation `json:"location"` // 返回值位置 + DataPath string `json:"data_path"` // 返回值的路径 + DataType consts.DataType `json:"data_type"` // 返回值类型 +} + +// MeshResponse 聚合请求响应结果 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 14:40 2025/3/28 +type MeshResponse struct { + Raw []byte `json:"raw"` // 返回结果的raw数据(按照result_rule格式化后的结果) + DataMap map[string]any `json:"data_map"` // 返回结果的map格式(按照result_rule格式化后的结果) + AliasResultTable map[string]Response `json:"alias_result_table"` // 每一个请求的返回结果 key: 请求别名 value: 请求返回数据 + Lock *sync.RWMutex `json:"-"` // 数据锁, public, 外部拿到结果需要做一席并发读写操作, 可以直接服用这把所 +} diff --git a/httpclient/mesh/mesh.go b/httpclient/mesh/mesh.go new file mode 100644 index 0000000..b440d4d --- /dev/null +++ b/httpclient/mesh/mesh.go @@ -0,0 +1,8 @@ +// Package mesh ... +// +// Description : mesh ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2025-03-28 14:11 +package mesh