Last active
June 29, 2024 23:30
-
-
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
This file contains 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 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