增加object类型
This commit is contained in:
parent
73bfcb0a5d
commit
eaf5c8f1ef
40
object.go
40
object.go
@ -7,9 +7,47 @@
|
||||
// Date : 2023-06-01 18:33
|
||||
package wrapper
|
||||
|
||||
func ObjectData(data map[string]interface{}) {
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// ObjectData 对象类型, 支持 nil / Map / Struct
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:36 2023/6/1
|
||||
func ObjectData(data interface{}) *ObjectType {
|
||||
ot := &ObjectType{
|
||||
source: data,
|
||||
data: map[interface{}]interface{}{},
|
||||
byteData: []byte{},
|
||||
isValid: true,
|
||||
}
|
||||
if nil == ot {
|
||||
return ot
|
||||
}
|
||||
reflectType := reflect.TypeOf(data)
|
||||
switch reflectType.Kind() {
|
||||
case reflect.Map:
|
||||
fallthrough
|
||||
case reflect.Struct:
|
||||
ot.byteData, _ = json.Marshal(ot.source)
|
||||
default:
|
||||
// 数据类型不是 nil / map / struct 质疑
|
||||
ot.isValid = false
|
||||
}
|
||||
return ot
|
||||
}
|
||||
|
||||
// ObjectType ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:38 2023/6/1
|
||||
type ObjectType struct {
|
||||
source interface{}
|
||||
data map[interface{}]interface{}
|
||||
byteData []byte
|
||||
isValid bool
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user