How to check for an empty object in Go

I typically perform comprehensive checks on various data structures (such as struct, array, slice, map, pointer, etc.) but prefer to avoid excessive if statements for object validation. Consequently, I developed a utility package for object validation to streamline this process, leveraging the capabilities of the Go reflection package. package check import ( "reflect" ) func IsEmpty(obj interface{}) bool { if obj == nil { return true } objValue := reflect.ValueOf(obj) switch objValue....

June 3, 2021 · 1 min · 127 words · Mecit Semerci