Skip to content

Instantly share code, notes, and snippets.

@xigang
Created April 7, 2016 02:23
Show Gist options
  • Select an option

  • Save xigang/c52cbd5c03f69e84be7729e75c31e307 to your computer and use it in GitHub Desktop.

Select an option

Save xigang/c52cbd5c03f69e84be7729e75c31e307 to your computer and use it in GitHub Desktop.
判断路径及文件是否存在
// internal utility methods
func webTime(t time.Time) string {
ftime := t.Format(time.RFC1123)
if strings.HasSuffix(ftime, "UTC") {
ftime = ftime[0:len(ftime)-3] + "GMT"
}
return ftime
}
func dirExists(dir string) bool {
d, e := os.Stat(dir)
switch {
case e != nil:
return false
case !d.IsDir():
return false
}
return true
}
func fileExists(dir string) bool {
info, err := os.Stat(dir)
if err != nil {
return false
}
return !info.IsDir()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment