Created
March 22, 2017 09:15
-
-
Save DavadDi/edff40a51ad349321e38876760957db2 to your computer and use it in GitHub Desktop.
用于检查一个变量是否为空,支持指针类型
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func IsEmpty(v interface{}) bool { | |
rt := reflect.TypeOf(v) | |
if rt.Kind() == reflect.Ptr { | |
rt = rt.Elem() | |
return reflect.DeepEqual(v, reflect.New(rt).Interface()) | |
} | |
return reflect.DeepEqual(v, reflect.Zero(rt).Interface()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment