Skip to content

Instantly share code, notes, and snippets.

@a3linux
Created October 21, 2016 01:36
Show Gist options
  • Select an option

  • Save a3linux/af22bfabeac0c6775f16721cdf670d2a to your computer and use it in GitHub Desktop.

Select an option

Save a3linux/af22bfabeac0c6775f16721cdf670d2a to your computer and use it in GitHub Desktop.
// 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