Support utils.FileExists/1

Support predicate for checking if a file exists on disk.
This commit is contained in:
William Carroll 2020-02-11 17:01:56 +00:00
parent 3ae3b6f039
commit b3b343ebf9

View file

@ -7,6 +7,7 @@ import (
"log" "log"
"net/http" "net/http"
"net/http/httputil" "net/http/httputil"
"os"
"os/user" "os/user"
) )
@ -19,6 +20,15 @@ func HomeDir() string {
return user.HomeDir return user.HomeDir
} }
// Return true if `path` exists and false otherwise.
func FileExists(path string) bool {
if _, err := os.Stat(path); os.IsNotExist(err) {
return false
} else {
return true
}
}
// Call log.Fatal with `err` when it's not nil. // Call log.Fatal with `err` when it's not nil.
func FailOn(err error) { func FailOn(err error) {
if err != nil { if err != nil {