From c8d3a6688fbb6e2af25aa016cf279d158e06baeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Thu, 2 Feb 2023 14:47:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8F=90=E5=8F=96=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E6=95=B0=E6=8D=AE=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reflect.go | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/reflect.go b/reflect.go index 26a1da3..9e34abb 100644 --- a/reflect.go +++ b/reflect.go @@ -8,8 +8,11 @@ package event import ( + "encoding/json" "git.zhangdeman.cn/zhangdeman/event/abstract" "git.zhangdeman.cn/zhangdeman/util" + "github.com/tidwall/gjson" + "net/http" "reflect" "strings" "sync" @@ -322,3 +325,72 @@ func (rv *ReflectValue) isZeroInputFieldValue(reflectValue reflect.Value, fieldI } return false } + +// fillFieldValue 填充字段值 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 14:00 2023/2/2 +func (rv *ReflectValue) fillFieldValue(reflectValue reflect.Value, fieldInfo *StructField, preSendHandler abstract.IPreSendHandler) { + paramByte, _ := json.Marshal(preSendHandler.GetRequestParam()) + header := preSendHandler.GetRequestHeader() + responseByte, _ := json.Marshal(preSendHandler.GetResponseData()) + extensionByte, _ := json.Marshal(preSendHandler.GetExtensionData()) + for _, item := range fieldInfo.MappingRuleList { + + } +} + +// getInputValue 获取输入的值 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 14:24 2023/2/2 +func (rv *ReflectValue) setDataValue(reflectVal reflect.Value, fieldInfo *StructField, rule MappingRuleItem, header http.Header, paramByte, responseByte, extensionByte []byte) bool { + switch rule.Location { + case MappingLocationHeader: + str := header.Get(rule.Field) + if len(str) == 0 { + // 未进行值设置 + return false + } + case MappingLocationParam: + case MappingLocationResponse: + case MappingLocationExtension: + default: + return false + } + return true +} + +// getInputValue 获取输入的值 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 14:43 2023/2/2 +func (rv *ReflectValue) getInputValue(rule MappingRuleItem, header http.Header, paramByte, responseByte, extensionByte []byte) string { + switch rule.Location { + case MappingLocationHeader: + return header.Get(rule.Field) + case MappingLocationParam: + return gjson.GetBytes(paramByte, rule.Field).String() + case MappingLocationResponse: + return gjson.GetBytes(responseByte, rule.Field).String() + case MappingLocationExtension: + return gjson.GetBytes(extensionByte, rule.Field).String() + case MappingLocationAll: + str := header.Get(rule.Field) + if len(str) == 0 { + str = gjson.GetBytes(paramByte, rule.Field).String() + } + if len(str) == 0 { + str = gjson.GetBytes(responseByte, rule.Field).String() + } + if len(str) == 0 { + str = gjson.GetBytes(extensionByte, rule.Field).String() + } + return str + default: + return "" + } +}