Skip to content

Instantly share code, notes, and snippets.

@Nidal-Bakir
Last active June 29, 2024 23:30
Show Gist options
  • Save Nidal-Bakir/e974d90bad892350d8f34e638c400bdf to your computer and use it in GitHub Desktop.
Save Nidal-Bakir/e974d90bad892350d8f34e638c400bdf to your computer and use it in GitHub Desktop.
Check if a Golang interface is valid (not nil) and does not point to a possibly nil value
func IsValidInterface(i interface{}) bool {
iv := reflect.ValueOf(i)
return iv.IsValid() && !iv.IsNil()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment