增加数据映射规则的定义
This commit is contained in:
		
							
								
								
									
										45
									
								
								filter.go
									
									
									
									
									
								
							
							
						
						
									
										45
									
								
								filter.go
									
									
									
									
									
								
							@ -7,15 +7,31 @@
 | 
			
		||||
// Date : 2022-07-04 11:45
 | 
			
		||||
package util
 | 
			
		||||
 | 
			
		||||
import "github.com/Jeffail/gabs"
 | 
			
		||||
 | 
			
		||||
// MapRule 映射规则
 | 
			
		||||
//
 | 
			
		||||
// Author : go_developer@163.com<白茶清欢>
 | 
			
		||||
//
 | 
			
		||||
// Date : 12:21 2022/7/4
 | 
			
		||||
type MapRule struct {
 | 
			
		||||
	SourcePath   string `json:"source_path"`   // 原路径
 | 
			
		||||
	MapPath      string `json:"map_path"`      // 映射路径
 | 
			
		||||
	Required     bool   `json:"required"`      // 必须存在
 | 
			
		||||
	DataType     string `json:"data_type"`     // 数据类型
 | 
			
		||||
	DefaultValue string `json:"default_value"` // 默认值, 以字符串传入, 会转换成 DataType
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NewFilter 过滤器实例
 | 
			
		||||
//
 | 
			
		||||
// Author : go_developer@163.com<白茶清欢>
 | 
			
		||||
//
 | 
			
		||||
// Date : 11:54 2022/7/4
 | 
			
		||||
func NewFilter(sourceData []byte, filterRule map[string]string) *filter {
 | 
			
		||||
func NewFilter(sourceData []byte, filterRuleList []MapRule) *filter {
 | 
			
		||||
	return &filter{
 | 
			
		||||
		sourceData: sourceData,
 | 
			
		||||
		filterRule: filterRule,
 | 
			
		||||
		sourceData:     sourceData,
 | 
			
		||||
		filterRuleList: filterRuleList,
 | 
			
		||||
		jsonObj:        &gabs.Container{},
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -25,6 +41,25 @@ func NewFilter(sourceData []byte, filterRule map[string]string) *filter {
 | 
			
		||||
//
 | 
			
		||||
// Date : 11:58 2022/7/4
 | 
			
		||||
type filter struct {
 | 
			
		||||
	sourceData []byte
 | 
			
		||||
	filterRule map[string]string
 | 
			
		||||
	sourceData     []byte
 | 
			
		||||
	filterRuleList []MapRule
 | 
			
		||||
	jsonObj        *gabs.Container // 生成的json对象实例
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Deal ...
 | 
			
		||||
//
 | 
			
		||||
// Author : go_developer@163.com<白茶清欢>
 | 
			
		||||
//
 | 
			
		||||
// Date : 11:59 2022/7/4
 | 
			
		||||
func (f *filter) Deal() ([]byte, error) {
 | 
			
		||||
	return nil, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// getDefaultValue 获取默认值
 | 
			
		||||
//
 | 
			
		||||
// Author : go_developer@163.com<白茶清欢>
 | 
			
		||||
//
 | 
			
		||||
// Date : 12:25 2022/7/4
 | 
			
		||||
func (f *filter) getDefaultValue(dataType string, defaultValue string) (interface{}, error) {
 | 
			
		||||
	return nil, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user