Add util
This commit is contained in:
15
util/file/file.go
Normal file
15
util/file/file.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package file
|
||||
|
||||
import "os"
|
||||
|
||||
// Exists returns true if the path is existing
|
||||
func Exists(path string) (bool, error) {
|
||||
_, err := os.Stat(path)
|
||||
if err == nil {
|
||||
return true, nil
|
||||
}
|
||||
if os.IsNotExist(err) {
|
||||
return false, nil
|
||||
}
|
||||
return true, err
|
||||
}
|
||||
17
util/file/file_test.go
Normal file
17
util/file/file_test.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package file
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestExists(t *testing.T) {
|
||||
ok, err := Exists("/")
|
||||
|
||||
if ok {
|
||||
return
|
||||
}
|
||||
|
||||
if !ok || err != nil {
|
||||
t.Fatalf("Test Exists fail, %s", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user