Created
October 21, 2016 01:36
-
-
Save a3linux/af22bfabeac0c6775f16721cdf670d2a 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
| // Check isDir in golang | |
| // use a switch to make it a bit cleaner | |
| fi, err := file.Stat(); | |
| switch { | |
| case err != nil: | |
| // handle the error and return | |
| case fi.IsDir(): | |
| // it's a directory | |
| default: | |
| // it's not a directory | |
| } | |
| check both in one if: | |
| if fi, err := file.Stat(); err != nil || fi.IsDir() { | |
| // error or is directory | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment