Skip to content

Instantly share code, notes, and snippets.

@DavadDi
Created March 22, 2017 09:15
Show Gist options
  • Save DavadDi/edff40a51ad349321e38876760957db2 to your computer and use it in GitHub Desktop.
Save DavadDi/edff40a51ad349321e38876760957db2 to your computer and use it in GitHub Desktop.
用于检查一个变量是否为空,支持指针类型
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