feat(reflect tool):增加类型校验
This commit is contained in:
@@ -44,6 +44,9 @@ func GetStructFieldTypeMap(i interface{}) map[string]interface{} {
|
|||||||
* @description
|
* @description
|
||||||
*/
|
*/
|
||||||
func GetPtrFieldTypeMap(i interface{}) map[string]interface{} {
|
func GetPtrFieldTypeMap(i interface{}) map[string]interface{} {
|
||||||
|
if GetValueType(i) != reflect.Ptr {
|
||||||
|
panic("该方法只支持结构体指针对象")
|
||||||
|
}
|
||||||
|
|
||||||
var m map[string]interface{}
|
var m map[string]interface{}
|
||||||
m = make(map[string]interface{})
|
m = make(map[string]interface{})
|
||||||
@@ -68,6 +71,9 @@ func GetPtrFieldTypeMap(i interface{}) map[string]interface{} {
|
|||||||
* @description
|
* @description
|
||||||
*/
|
*/
|
||||||
func GetStructTypeFieldNameList(t reflect.Type) []string {
|
func GetStructTypeFieldNameList(t reflect.Type) []string {
|
||||||
|
if t.Kind() != reflect.Struct {
|
||||||
|
panic("该方法只支持结构体类型")
|
||||||
|
}
|
||||||
list := make([]string, 0)
|
list := make([]string, 0)
|
||||||
|
|
||||||
for i := 0; i < t.NumField(); i++ {
|
for i := 0; i < t.NumField(); i++ {
|
||||||
@@ -86,6 +92,9 @@ func GetStructTypeFieldNameList(t reflect.Type) []string {
|
|||||||
* @description
|
* @description
|
||||||
*/
|
*/
|
||||||
func GetPtrTypeFieldNameList(t reflect.Type) []string {
|
func GetPtrTypeFieldNameList(t reflect.Type) []string {
|
||||||
|
if t.Kind() != reflect.Ptr {
|
||||||
|
panic("该方法只支持结构体指针类型")
|
||||||
|
}
|
||||||
list := make([]string, 0)
|
list := make([]string, 0)
|
||||||
|
|
||||||
typ := t.Elem()
|
typ := t.Elem()
|
||||||
|
|||||||
Reference in New Issue
Block a user