util/common: add PathExists helper
Just basic helper function that's handy to have around. Not used yet.
package util
import (
+ "os"
"unsafe"
)
@@ -50,3 +51,14 @@ func StrToPtr(s string) *string {
func BoolToPtr(b bool) *bool {
return &b
}
+
+func PathExists(path string) (bool, error) {
+ _, err := os.Stat(path)
+ if err != nil {
+ if os.IsNotExist(err) {
+ return false, nil
+ }
+ return false, err
+ }
+ return true, nil
+}
