增加提取输入数据的方法
This commit is contained in:
parent
9b3600643b
commit
c8d3a6688f
72
reflect.go
72
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 ""
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user