增加任意类型定义以及类型获取
This commit is contained in:
parent
d46ebe684c
commit
e48ace48ab
65
any.go
Normal file
65
any.go
Normal file
@ -0,0 +1,65 @@
|
||||
// Package wrapper ...
|
||||
//
|
||||
// Description : wrapper ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2023-06-01 18:18
|
||||
package wrapper
|
||||
|
||||
import "reflect"
|
||||
|
||||
// AnyDataType ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:19 2023/6/1
|
||||
func AnyDataType(data interface{}) *AnyType {
|
||||
return &AnyType{
|
||||
data: data,
|
||||
}
|
||||
}
|
||||
|
||||
// AnyType ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:19 2023/6/1
|
||||
type AnyType struct {
|
||||
data interface{}
|
||||
}
|
||||
|
||||
// IsNil 是否为 nil
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:21 2023/6/1
|
||||
func (at *AnyType) IsNil() bool {
|
||||
return at.data == nil
|
||||
}
|
||||
|
||||
// Type 获取类型
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:22 2023/6/1
|
||||
func (at *AnyType) Type() string {
|
||||
if at.IsNil() {
|
||||
return DataTypeNil
|
||||
}
|
||||
reflectType := reflect.TypeOf(at.data)
|
||||
switch reflectType.Kind() {
|
||||
case reflect.Slice:
|
||||
return DataTypeAnySlice
|
||||
case reflect.Array:
|
||||
return DataTypeAnySlice
|
||||
case reflect.Map:
|
||||
return DataTypeAnyObject
|
||||
case reflect.Struct:
|
||||
return DataTypeAnyObject
|
||||
case reflect.Pointer:
|
||||
return DataTypePtr
|
||||
default:
|
||||
return reflectType.Kind().String()
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user