Compare commits
1 Commits
46cd353dd6
...
feature/ge
Author | SHA1 | Date | |
---|---|---|---|
50aa5ae7f8 |
17
any.go
17
any.go
@ -43,18 +43,7 @@ type AnyType struct {
|
|||||||
//
|
//
|
||||||
// Date : 18:21 2023/6/1
|
// Date : 18:21 2023/6/1
|
||||||
func (at *AnyType) IsNil() bool {
|
func (at *AnyType) IsNil() bool {
|
||||||
if at.data == nil {
|
return at.data == nil
|
||||||
return true
|
|
||||||
}
|
|
||||||
reflectValue := reflect.ValueOf(at.data)
|
|
||||||
switch reflectValue.Kind() {
|
|
||||||
case reflect.Chan, reflect.Func, reflect.Map,
|
|
||||||
reflect.Pointer, reflect.UnsafePointer,
|
|
||||||
reflect.Interface, reflect.Slice:
|
|
||||||
return reflectValue.IsNil()
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type 获取类型
|
// Type 获取类型
|
||||||
@ -108,7 +97,7 @@ func (at *AnyType) ToString() String {
|
|||||||
case consts.DataTypeSliceAny:
|
case consts.DataTypeSliceAny:
|
||||||
var val []any
|
var val []any
|
||||||
_ = serialize.JSON.Transition(at.data, &val)
|
_ = serialize.JSON.Transition(at.data, &val)
|
||||||
return String(ArrayType[any](val).ToString().Value)
|
return String(ArrayType[any, any](val).ToString().Value)
|
||||||
case consts.DataTypeMapAnyAny:
|
case consts.DataTypeMapAnyAny:
|
||||||
return String(EasyMap(at.data).ToString())
|
return String(EasyMap(at.data).ToString())
|
||||||
case consts.DataTypeInt:
|
case consts.DataTypeInt:
|
||||||
@ -120,6 +109,6 @@ func (at *AnyType) ToString() String {
|
|||||||
case consts.DataTypeBool:
|
case consts.DataTypeBool:
|
||||||
return String(fmt.Sprintf("%v", at.data))
|
return String(fmt.Sprintf("%v", at.data))
|
||||||
default:
|
default:
|
||||||
return String(serialize.JSON.MarshalForStringIgnoreError(at.data))
|
return String(serialize.JSON.MarshalForString(at.data))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
68
array.go
68
array.go
@ -9,6 +9,7 @@ package wrapper
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"git.zhangdeman.cn/zhangdeman/op_type"
|
"git.zhangdeman.cn/zhangdeman/op_type"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -20,8 +21,8 @@ import (
|
|||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 21:03 2023/6/11
|
// Date : 21:03 2023/6/11
|
||||||
func ArrayType[Bt op_type.BaseType](value []Bt) *Array[Bt] {
|
func ArrayType[Bt op_type.BaseType, ExtractDataType op_type.BaseType](value []Bt) *Array[Bt, ExtractDataType] {
|
||||||
at := &Array[Bt]{
|
at := &Array[Bt, ExtractDataType]{
|
||||||
value: value,
|
value: value,
|
||||||
}
|
}
|
||||||
return at
|
return at
|
||||||
@ -32,7 +33,7 @@ func ArrayType[Bt op_type.BaseType](value []Bt) *Array[Bt] {
|
|||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 21:05 2023/6/11
|
// Date : 21:05 2023/6/11
|
||||||
type Array[Bt op_type.BaseType] struct {
|
type Array[Bt op_type.BaseType, ExtractDataType op_type.BaseType] struct {
|
||||||
value []Bt
|
value []Bt
|
||||||
convertErr error
|
convertErr error
|
||||||
itemType reflect.Kind // 简单list场景下, 每一项的数据类型
|
itemType reflect.Kind // 简单list场景下, 每一项的数据类型
|
||||||
@ -43,7 +44,7 @@ type Array[Bt op_type.BaseType] struct {
|
|||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 21:11 2023/6/11
|
// Date : 21:11 2023/6/11
|
||||||
func (at *Array[Bt]) IsNil() bool {
|
func (at *Array[Bt, ExtractDataType]) IsNil() bool {
|
||||||
return at.value == nil
|
return at.value == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +53,7 @@ func (at *Array[Bt]) IsNil() bool {
|
|||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 11:42 2024/4/22
|
// Date : 11:42 2024/4/22
|
||||||
func (at *Array[Bt]) ToStringSlice() []string {
|
func (at *Array[Bt, ExtractDataType]) ToStringSlice() []string {
|
||||||
list := make([]string, 0)
|
list := make([]string, 0)
|
||||||
for _, item := range at.value {
|
for _, item := range at.value {
|
||||||
byteData, _ := json.Marshal(item)
|
byteData, _ := json.Marshal(item)
|
||||||
@ -66,7 +67,7 @@ func (at *Array[Bt]) ToStringSlice() []string {
|
|||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 17:43 2023/6/12
|
// Date : 17:43 2023/6/12
|
||||||
func (at *Array[Bt]) Unique() []Bt {
|
func (at *Array[Bt, ExtractDataType]) Unique() []Bt {
|
||||||
result := make([]Bt, 0)
|
result := make([]Bt, 0)
|
||||||
dataTable := make(map[string]bool)
|
dataTable := make(map[string]bool)
|
||||||
|
|
||||||
@ -91,7 +92,7 @@ func (at *Array[Bt]) Unique() []Bt {
|
|||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 16:28 2023/7/31
|
// Date : 16:28 2023/7/31
|
||||||
func (at *Array[Bt]) Has(input Bt) int {
|
func (at *Array[Bt, ExtractDataType]) Has(input Bt) int {
|
||||||
for idx := 0; idx < len(at.value); idx++ {
|
for idx := 0; idx < len(at.value); idx++ {
|
||||||
if reflect.TypeOf(at.value[idx]).String() != reflect.TypeOf(input).String() {
|
if reflect.TypeOf(at.value[idx]).String() != reflect.TypeOf(input).String() {
|
||||||
// 类型不同
|
// 类型不同
|
||||||
@ -112,7 +113,7 @@ func (at *Array[Bt]) Has(input Bt) int {
|
|||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 16:57 2023/9/28
|
// Date : 16:57 2023/9/28
|
||||||
func (at *Array[Bt]) ToString() StringResult {
|
func (at *Array[Bt, ExtractDataType]) ToString() StringResult {
|
||||||
if at.IsNil() {
|
if at.IsNil() {
|
||||||
return StringResult{
|
return StringResult{
|
||||||
Value: "",
|
Value: "",
|
||||||
@ -131,7 +132,7 @@ func (at *Array[Bt]) ToString() StringResult {
|
|||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 17:42 2023/10/25
|
// Date : 17:42 2023/10/25
|
||||||
func (at *Array[Bt]) ToStringWithSplit(split string) StringResult {
|
func (at *Array[Bt, ExtractDataType]) ToStringWithSplit(split string) StringResult {
|
||||||
if at.IsNil() {
|
if at.IsNil() {
|
||||||
return StringResult{
|
return StringResult{
|
||||||
Value: "",
|
Value: "",
|
||||||
@ -144,23 +145,46 @@ func (at *Array[Bt]) ToStringWithSplit(split string) StringResult {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExtraField 提取[]map/[]struct 中的指定字段, 并以list形式返回
|
// ExtractField 提取指定字段, 转换成数组
|
||||||
//
|
//
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 19:00 2024/10/13
|
// Date : 15:24 2024/8/6
|
||||||
func (at *Array[Bt]) ExtraField(fieldName string) String {
|
func (at *Array[Bt, ExtractDataType]) ExtractField(fieldPath string) ([]ExtractDataType, error) {
|
||||||
if at.IsNil() {
|
strValResult := at.ToString()
|
||||||
return String("[]")
|
if nil != strValResult.Err {
|
||||||
|
return make([]ExtractDataType, 0), nil
|
||||||
}
|
}
|
||||||
byteData, _ := json.Marshal(at.value)
|
gjsonResult := gjson.Parse(strValResult.Value)
|
||||||
res := make([]any, 0)
|
if !gjsonResult.IsArray() {
|
||||||
list := gjson.ParseBytes(byteData).Array()
|
return make([]ExtractDataType, 0), errors.New("input value is not slice")
|
||||||
for _, item := range list {
|
}
|
||||||
itemValue := item.Get(fieldName)
|
arrList := gjsonResult.Array()
|
||||||
if itemValue.Exists() {
|
if len(arrList) == 0 {
|
||||||
res = append(res, itemValue.Value())
|
return make([]ExtractDataType, 0), nil
|
||||||
|
}
|
||||||
|
res := make([]ExtractDataType, 0)
|
||||||
|
for _, item := range arrList {
|
||||||
|
valueResult := item.Get(fieldPath)
|
||||||
|
if !valueResult.Exists() {
|
||||||
|
// 不存在
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
var val ExtractDataType
|
||||||
|
if err := ConvertAssign(&val, valueResult.String()); nil != err {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
res = append(res, val)
|
||||||
}
|
}
|
||||||
return String(ArrayType(res).ToString().Value)
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExtractFieldIgnoreError 提取指定字段并忽略异常
|
||||||
|
//
|
||||||
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
//
|
||||||
|
// Date : 15:28 2024/8/6
|
||||||
|
func (at *Array[Bt, ExtractDataType]) ExtractFieldIgnoreError(field string) []ExtractDataType {
|
||||||
|
res, _ := at.ExtractField(field)
|
||||||
|
return res
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,24 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestArray_Unique(t *testing.T) {
|
func TestArray_Unique(t *testing.T) {
|
||||||
fmt.Println(ArrayType([]any{"1", 1, 1, "1", 2, 3}).Unique())
|
fmt.Println(ArrayType[any, any]([]any{"1", 1, 1, "1", 2, 3}).Unique())
|
||||||
fmt.Println(ArrayType([]int{1, 1, 2, 3}).Unique())
|
fmt.Println(ArrayType[int, any]([]int{1, 1, 2, 3}).Unique())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestArray_ExtractField(t *testing.T) {
|
||||||
|
testMap := []any{
|
||||||
|
map[string]any{
|
||||||
|
"age": 18,
|
||||||
|
"name": "baicha",
|
||||||
|
},
|
||||||
|
map[string]any{
|
||||||
|
"age": 20,
|
||||||
|
"name": "qinghuan",
|
||||||
|
},
|
||||||
|
map[string]any{
|
||||||
|
"foo": "bar",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
fmt.Println(ArrayType[any, int](testMap).ExtractField("age"))
|
||||||
|
fmt.Println(ArrayType[any, string](testMap).ExtractField("name"))
|
||||||
}
|
}
|
||||||
|
@ -1,198 +0,0 @@
|
|||||||
// Package wrapper ...
|
|
||||||
//
|
|
||||||
// Description : wrapper ...
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 2024-08-21 16:43
|
|
||||||
package wrapper
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
)
|
|
||||||
|
|
||||||
func NewDynamic() *DynamicStruct {
|
|
||||||
return &DynamicStruct{
|
|
||||||
structFieldList: make([]reflect.StructField, 0),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// DynamicStruct 动态生成数据结构
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 16:48 2024/8/21
|
|
||||||
type DynamicStruct struct {
|
|
||||||
structFieldList []reflect.StructField // 结构体字段列表
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddInt 添加int字段统一Int64
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 17:50 2024/8/21
|
|
||||||
func (ds *DynamicStruct) AddInt(fieldName string, fieldTag string, pkgPath string) {
|
|
||||||
ds.AddStructField(reflect.StructField{
|
|
||||||
Name: fieldName,
|
|
||||||
PkgPath: pkgPath,
|
|
||||||
Type: reflect.TypeOf(int64(0)),
|
|
||||||
Tag: reflect.StructTag(fmt.Sprintf(`json:"%v"`, fieldTag)),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddUint 添加uint字段, 统一 uint64
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 17:50 2024/8/21
|
|
||||||
func (ds *DynamicStruct) AddUint(fieldName string, fieldTag string, pkgPath string) {
|
|
||||||
ds.AddStructField(reflect.StructField{
|
|
||||||
Name: fieldName,
|
|
||||||
PkgPath: pkgPath,
|
|
||||||
Type: reflect.TypeOf(uint64(0)),
|
|
||||||
Tag: reflect.StructTag(fieldTag),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddString 添加字符串字段
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 17:49 2024/8/21
|
|
||||||
func (ds *DynamicStruct) AddString(fieldName string, fieldTag string, pkgPath string) {
|
|
||||||
ds.AddStructField(reflect.StructField{
|
|
||||||
Name: fieldName,
|
|
||||||
PkgPath: pkgPath,
|
|
||||||
Type: reflect.TypeOf(""),
|
|
||||||
Tag: reflect.StructTag(fmt.Sprintf(`json:"%v"`, fieldTag)),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddBool 添加bool字段
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 17:49 2024/8/21
|
|
||||||
func (ds *DynamicStruct) AddBool(fieldName string, fieldTag string, pkgPath string) {
|
|
||||||
ds.AddStructField(reflect.StructField{
|
|
||||||
Name: fieldName,
|
|
||||||
PkgPath: pkgPath,
|
|
||||||
Type: reflect.TypeOf(true),
|
|
||||||
Tag: reflect.StructTag(fmt.Sprintf(`json:"%v"`, fieldTag)),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddFloat 添加float字段, 统一 float64
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 17:48 2024/8/21
|
|
||||||
func (ds *DynamicStruct) AddFloat(fieldName string, fieldTag string, pkgPath string) {
|
|
||||||
ds.AddStructField(reflect.StructField{
|
|
||||||
Name: fieldName,
|
|
||||||
PkgPath: pkgPath,
|
|
||||||
Type: reflect.TypeOf(float64(0)),
|
|
||||||
Tag: reflect.StructTag(fmt.Sprintf(`json:"%v"`, fieldTag)),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddSlice 添加slice
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 17:47 2024/8/21
|
|
||||||
func (ds *DynamicStruct) AddSlice(fieldName string, fieldTag string, pkgPath string) {
|
|
||||||
ds.AddStructField(reflect.StructField{
|
|
||||||
Name: fieldName,
|
|
||||||
PkgPath: pkgPath,
|
|
||||||
Type: reflect.TypeOf([]any{}),
|
|
||||||
Tag: reflect.StructTag(fieldTag),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddMap 添加map字段
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 17:43 2024/8/21
|
|
||||||
func (ds *DynamicStruct) AddMap(fieldName string, fieldTag string, pkgPath string) {
|
|
||||||
ds.AddStructField(reflect.StructField{
|
|
||||||
Name: fieldName,
|
|
||||||
PkgPath: pkgPath,
|
|
||||||
Type: reflect.TypeOf(map[string]any{}),
|
|
||||||
Tag: reflect.StructTag(fieldTag),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddAny 添加任意类型字段
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 17:52 2024/8/21
|
|
||||||
func (ds *DynamicStruct) AddAny(fieldName string, fieldTag string, pkgPath string, value any) {
|
|
||||||
if nil == value {
|
|
||||||
// 不能是空指针
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ds.AddStructField(reflect.StructField{
|
|
||||||
Name: fieldName,
|
|
||||||
PkgPath: pkgPath,
|
|
||||||
Type: reflect.TypeOf(value),
|
|
||||||
Tag: reflect.StructTag(fieldTag),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddStructField 添加结构体字段
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 17:42 2024/8/21
|
|
||||||
func (ds *DynamicStruct) AddStructField(field reflect.StructField) {
|
|
||||||
if field.Tag == "" {
|
|
||||||
field.Tag = reflect.StructTag(fmt.Sprintf(`json:"%v"`, field.Name))
|
|
||||||
}
|
|
||||||
field.Name = String(field.Name).SnakeCaseToCamel() // 转成大驼峰, 保证对外可访问
|
|
||||||
ds.structFieldList = append(ds.structFieldList, field)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetStructType 获取结构体的类型
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 16:58 2024/8/21
|
|
||||||
func (ds *DynamicStruct) GetStructType() reflect.Type {
|
|
||||||
return reflect.StructOf(ds.structFieldList)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ToStructDefaultValue 获取结构体的值, 并采用对应类型默认值填充相关字段
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 16:56 2024/8/21
|
|
||||||
func (ds *DynamicStruct) ToStructDefaultValue() any {
|
|
||||||
defer ds.Clear()
|
|
||||||
defaultValue := reflect.New(ds.GetStructType()).Elem().Interface()
|
|
||||||
return defaultValue
|
|
||||||
}
|
|
||||||
|
|
||||||
// ToStructDefaultSliceValue 自动生成结构体列表
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 17:04 2024/8/21
|
|
||||||
func (ds *DynamicStruct) ToStructDefaultSliceValue() any {
|
|
||||||
defer ds.Clear()
|
|
||||||
tSlice := reflect.MakeSlice(reflect.SliceOf(ds.GetStructType()), 0, 0)
|
|
||||||
return reflect.New(tSlice.Type()).Elem().Interface()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear 清理
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 17:08 2024/8/21
|
|
||||||
func (ds *DynamicStruct) Clear() {
|
|
||||||
// 清理掉已设置的字段, 不然实例复用会互相影响
|
|
||||||
ds.structFieldList = make([]reflect.StructField, 0)
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
// Package wrapper ...
|
|
||||||
//
|
|
||||||
// Description : wrapper ...
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 2024-08-21 17:56
|
|
||||||
package wrapper
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/mitchellh/mapstructure"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestNewDynamic(t *testing.T) {
|
|
||||||
instance := NewDynamic()
|
|
||||||
instance.AddInt("Age", "age", "")
|
|
||||||
instance.AddString("Name", "name", "")
|
|
||||||
defaultVal := instance.ToStructDefaultValue()
|
|
||||||
testMap := map[string]any{
|
|
||||||
"name": "白茶",
|
|
||||||
"age": 18,
|
|
||||||
}
|
|
||||||
_ = mapstructure.Decode(testMap, &defaultVal)
|
|
||||||
fmt.Println(defaultVal)
|
|
||||||
}
|
|
11
go.mod
11
go.mod
@ -5,14 +5,14 @@ go 1.21
|
|||||||
toolchain go1.21.4
|
toolchain go1.21.4
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241104082108-0f97a870bbc3
|
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240726024939-e424db29c5c4
|
||||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20241101082529-28a6c68e38a4
|
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211
|
||||||
git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20240122104027-4928421213c0
|
git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20240122104027-4928421213c0
|
||||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20241104092308-ecb02113459e
|
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240618035451-8d48a6bd39dd
|
||||||
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394
|
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394
|
||||||
github.com/spaolacci/murmur3 v1.1.0
|
github.com/spaolacci/murmur3 v1.1.0
|
||||||
github.com/stretchr/testify v1.9.0
|
github.com/stretchr/testify v1.8.4
|
||||||
github.com/tidwall/gjson v1.18.0
|
github.com/tidwall/gjson v1.17.3
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
@ -21,7 +21,6 @@ require (
|
|||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/go-ini/ini v1.67.0 // indirect
|
github.com/go-ini/ini v1.67.0 // indirect
|
||||||
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
|
||||||
github.com/mozillazg/go-pinyin v0.20.0 // indirect
|
github.com/mozillazg/go-pinyin v0.20.0 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/tidwall/match v1.1.1 // indirect
|
github.com/tidwall/match v1.1.1 // indirect
|
||||||
|
19
go.sum
19
go.sum
@ -10,20 +10,10 @@ git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240612081722-31c64d4d4ce7 h1:QR8vMX
|
|||||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240612081722-31c64d4d4ce7/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240612081722-31c64d4d4ce7/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
||||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240726024939-e424db29c5c4 h1:mibnyzYbZullK0aTHVASHl3UeoVr8IgytQZsuyv+yEM=
|
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240726024939-e424db29c5c4 h1:mibnyzYbZullK0aTHVASHl3UeoVr8IgytQZsuyv+yEM=
|
||||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240726024939-e424db29c5c4/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240726024939-e424db29c5c4/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
||||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240823041145-d4df71cf37e5 h1:pmIHln0gWW+5xAB762h3WDsRkZuYLUDndvJDsGMKoOY=
|
|
||||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240823041145-d4df71cf37e5/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
|
||||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241023090605-10cff9173059 h1:TPAYdTKKUjgxtCnK38d1Tb4teyQp1C7wYHPdR32yZtM=
|
|
||||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241023090605-10cff9173059/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
|
||||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241104082108-0f97a870bbc3 h1:BiAlBJ+DuRs/xD7nDQD2JT8Oc+V+0Uwt36qZwdXGvzI=
|
|
||||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20241104082108-0f97a870bbc3/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
|
||||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240130062251-a87a97b0e8d4 h1:93JYY8JLbFcrlq37q/uKyxs2r2e3modsjvfSbnZQ/UI=
|
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240130062251-a87a97b0e8d4 h1:93JYY8JLbFcrlq37q/uKyxs2r2e3modsjvfSbnZQ/UI=
|
||||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240130062251-a87a97b0e8d4/go.mod h1:SrtvrQRdzt+8KfYzvosH++gWxo2ShPTzR1m3VQ6uX7U=
|
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240130062251-a87a97b0e8d4/go.mod h1:SrtvrQRdzt+8KfYzvosH++gWxo2ShPTzR1m3VQ6uX7U=
|
||||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211 h1:I/wOsRpCSRkU9vo1u703slQsmK0wnNeZzsWQOGtIAG0=
|
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211 h1:I/wOsRpCSRkU9vo1u703slQsmK0wnNeZzsWQOGtIAG0=
|
||||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211/go.mod h1:SrtvrQRdzt+8KfYzvosH++gWxo2ShPTzR1m3VQ6uX7U=
|
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211/go.mod h1:SrtvrQRdzt+8KfYzvosH++gWxo2ShPTzR1m3VQ6uX7U=
|
||||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20241024134352-ce2d84d282ba h1:hgajrPZGoDY9P+x6iqcS06pnu5t+N7DOfpmRwb+TZ4s=
|
|
||||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20241024134352-ce2d84d282ba/go.mod h1:V4Dfg1v/JVIZGEKCm6/aehs8hK+Xow1dkL1yiQymXlQ=
|
|
||||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20241101082529-28a6c68e38a4 h1:s6d4b6yY+NaK1AzoBD1pxqsuygEHQz0Oie86c45geDw=
|
|
||||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20241101082529-28a6c68e38a4/go.mod h1:V4Dfg1v/JVIZGEKCm6/aehs8hK+Xow1dkL1yiQymXlQ=
|
|
||||||
git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20240122104027-4928421213c0 h1:gUDlQMuJ4xNfP2Abl1Msmpa3fASLWYkNlqDFF/6GN0Y=
|
git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20240122104027-4928421213c0 h1:gUDlQMuJ4xNfP2Abl1Msmpa3fASLWYkNlqDFF/6GN0Y=
|
||||||
git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20240122104027-4928421213c0/go.mod h1:VHb9qmhaPDAQDcS6vUiDCamYjZ4R5lD1XtVsh55KsMI=
|
git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20240122104027-4928421213c0/go.mod h1:VHb9qmhaPDAQDcS6vUiDCamYjZ4R5lD1XtVsh55KsMI=
|
||||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240110090803-399e964daa0c h1:k7VCn9GfRGTilvdF/TcTFVMDBfKLe3VeGAtMTiDSnS0=
|
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240110090803-399e964daa0c h1:k7VCn9GfRGTilvdF/TcTFVMDBfKLe3VeGAtMTiDSnS0=
|
||||||
@ -32,10 +22,6 @@ git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240325080031-1f58204e8687 h1:uQc
|
|||||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240325080031-1f58204e8687/go.mod h1:gf7SW2TXATgux8pfdFedMkXWv2515OtIIM/5c4atkFw=
|
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240325080031-1f58204e8687/go.mod h1:gf7SW2TXATgux8pfdFedMkXWv2515OtIIM/5c4atkFw=
|
||||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240618035451-8d48a6bd39dd h1:2Y37waOVCmVvx0Rp8VGEptE2/2JVMImtxB4dKKDk/3w=
|
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240618035451-8d48a6bd39dd h1:2Y37waOVCmVvx0Rp8VGEptE2/2JVMImtxB4dKKDk/3w=
|
||||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240618035451-8d48a6bd39dd/go.mod h1:6+7whkCmb4sJDIfH3HxNuXRveaM0gCCNWd2uXZqNtIE=
|
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240618035451-8d48a6bd39dd/go.mod h1:6+7whkCmb4sJDIfH3HxNuXRveaM0gCCNWd2uXZqNtIE=
|
||||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20241023104258-2e0a298aa558 h1:ZVJyyDKfYeA3TsN8UOi4IprkouK4wIIfCKe+F9byLWA=
|
|
||||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20241023104258-2e0a298aa558/go.mod h1:/9eicss/Dt9tp2jwZ/4cXDqDKo/Dez+HuT5/NGdqW+s=
|
|
||||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20241104092308-ecb02113459e h1:A045F67AMSqFKGD9kk2uLa+6c/zpmW8vjjSRmSsdjPs=
|
|
||||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20241104092308-ecb02113459e/go.mod h1:XqgER4jDYwskFgj2riJ9XptIjzgYWubY+Zq8iB2WkY0=
|
|
||||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20231227095334-7eb5cdbf9253 h1:GO3oZa5a2sqwAzGcLDJtQzmshSWRmoP7IDS8bwFqvC4=
|
git.zhangdeman.cn/zhangdeman/util v0.0.0-20231227095334-7eb5cdbf9253 h1:GO3oZa5a2sqwAzGcLDJtQzmshSWRmoP7IDS8bwFqvC4=
|
||||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20231227095334-7eb5cdbf9253/go.mod h1:VpPjBlwz8U+OxZuxzHQBv1aEEZ3pStH6bZvT21ADEbI=
|
git.zhangdeman.cn/zhangdeman/util v0.0.0-20231227095334-7eb5cdbf9253/go.mod h1:VpPjBlwz8U+OxZuxzHQBv1aEEZ3pStH6bZvT21ADEbI=
|
||||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20240618042405-6ee2c904644e h1:Q973S6CcWr1ICZhFI1STFOJ+KUImCl2BaIXm6YppBqI=
|
git.zhangdeman.cn/zhangdeman/util v0.0.0-20240618042405-6ee2c904644e h1:Q973S6CcWr1ICZhFI1STFOJ+KUImCl2BaIXm6YppBqI=
|
||||||
@ -52,8 +38,6 @@ github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
|
|||||||
github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
|
github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
|
||||||
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
|
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
|
||||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
|
||||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
|
||||||
github.com/mozillazg/go-pinyin v0.20.0 h1:BtR3DsxpApHfKReaPO1fCqF4pThRwH9uwvXzm+GnMFQ=
|
github.com/mozillazg/go-pinyin v0.20.0 h1:BtR3DsxpApHfKReaPO1fCqF4pThRwH9uwvXzm+GnMFQ=
|
||||||
github.com/mozillazg/go-pinyin v0.20.0/go.mod h1:iR4EnMMRXkfpFVV5FMi4FNB6wGq9NV6uDWbUuPhP4Yc=
|
github.com/mozillazg/go-pinyin v0.20.0/go.mod h1:iR4EnMMRXkfpFVV5FMi4FNB6wGq9NV6uDWbUuPhP4Yc=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
@ -62,11 +46,8 @@ github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0b
|
|||||||
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
|
||||||
github.com/tidwall/gjson v1.17.3 h1:bwWLZU7icoKRG+C+0PNwIKC6FCJO/Q3p2pZvuP0jN94=
|
github.com/tidwall/gjson v1.17.3 h1:bwWLZU7icoKRG+C+0PNwIKC6FCJO/Q3p2pZvuP0jN94=
|
||||||
github.com/tidwall/gjson v1.17.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
github.com/tidwall/gjson v1.17.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||||
github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY=
|
|
||||||
github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
|
||||||
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
|
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
|
||||||
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||||
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||||
|
2
map.go
2
map.go
@ -39,7 +39,7 @@ func EasyMapWithError(mapData any) (Map, error) {
|
|||||||
reflectType := reflect.TypeOf(mapData)
|
reflectType := reflect.TypeOf(mapData)
|
||||||
if reflectType.Kind() != reflect.Map {
|
if reflectType.Kind() != reflect.Map {
|
||||||
mapFormatData := make(map[string]any)
|
mapFormatData := make(map[string]any)
|
||||||
if err := serialize.JSON.UnmarshalWithNumber(serialize.JSON.MarshalForByteIgnoreError(mapData), &mapFormatData); nil != err {
|
if err := serialize.JSON.UnmarshalWithNumber(serialize.JSON.MarshalForByte(mapData), &mapFormatData); nil != err {
|
||||||
return m, errors.New("input data type is " + reflectType.String() + ", can not convert to map")
|
return m, errors.New("input data type is " + reflectType.String() + ", can not convert to map")
|
||||||
}
|
}
|
||||||
mapData = mapFormatData
|
mapData = mapFormatData
|
||||||
|
@ -71,10 +71,7 @@ func (ot *ObjectType) IsValid() bool {
|
|||||||
//
|
//
|
||||||
// Date : 18:50 2023/6/1
|
// Date : 18:50 2023/6/1
|
||||||
func (ot *ObjectType) IsNil() bool {
|
func (ot *ObjectType) IsNil() bool {
|
||||||
if ot.source == nil {
|
return ot.source == nil
|
||||||
return true
|
|
||||||
}
|
|
||||||
return reflect.ValueOf(ot.source).IsNil()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToString 转字符串
|
// ToString 转字符串
|
||||||
|
Reference in New Issue
Block a user