Merge pull request #362 from kyle-wang/master
rename some function name under /utils
Showing
2 changed files
with
6 additions
and
6 deletions
| ... | @@ -30,7 +30,7 @@ func FileExists(name string) bool { | ... | @@ -30,7 +30,7 @@ func FileExists(name string) bool { |
| 30 | 30 | ||
| 31 | // search a file in paths. | 31 | // search a file in paths. |
| 32 | // this is offen used in search config file in /etc ~/ | 32 | // this is offen used in search config file in /etc ~/ |
| 33 | func LookFile(filename string, paths ...string) (fullpath string, err error) { | 33 | func SearchFile(filename string, paths ...string) (fullpath string, err error) { |
| 34 | for _, path := range paths { | 34 | for _, path := range paths { |
| 35 | if fullpath = filepath.Join(path, filename); FileExists(fullpath) { | 35 | if fullpath = filepath.Join(path, filename); FileExists(fullpath) { |
| 36 | return | 36 | return |
| ... | @@ -41,7 +41,7 @@ func LookFile(filename string, paths ...string) (fullpath string, err error) { | ... | @@ -41,7 +41,7 @@ func LookFile(filename string, paths ...string) (fullpath string, err error) { |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | // like command grep -E | 43 | // like command grep -E |
| 44 | // for example: GrepE(`^hello`, "hello.txt") | 44 | // for example: GrepFile(`^hello`, "hello.txt") |
| 45 | // \n is striped while read | 45 | // \n is striped while read |
| 46 | func GrepFile(patten string, filename string) (lines []string, err error) { | 46 | func GrepFile(patten string, filename string) (lines []string, err error) { |
| 47 | re, err := regexp.Compile(patten) | 47 | re, err := regexp.Compile(patten) | ... | ... |
| ... | @@ -23,7 +23,7 @@ func TestSelfDir(t *testing.T) { | ... | @@ -23,7 +23,7 @@ func TestSelfDir(t *testing.T) { |
| 23 | 23 | ||
| 24 | func TestFileExists(t *testing.T) { | 24 | func TestFileExists(t *testing.T) { |
| 25 | if !FileExists("./file.go") { | 25 | if !FileExists("./file.go") { |
| 26 | t.Errorf("/bin/echo should exists, but it didn't") | 26 | t.Errorf("./file.go should exists, but it didn't") |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | if FileExists(noExistedFile) { | 29 | if FileExists(noExistedFile) { |
| ... | @@ -31,14 +31,14 @@ func TestFileExists(t *testing.T) { | ... | @@ -31,14 +31,14 @@ func TestFileExists(t *testing.T) { |
| 31 | } | 31 | } |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | func TestLookFile(t *testing.T) { | 34 | func TestSearchFile(t *testing.T) { |
| 35 | path, err := LookFile(filepath.Base(SelfPath()), SelfDir()) | 35 | path, err := SearchFile(filepath.Base(SelfPath()), SelfDir()) |
| 36 | if err != nil { | 36 | if err != nil { |
| 37 | t.Error(err) | 37 | t.Error(err) |
| 38 | } | 38 | } |
| 39 | t.Log(path) | 39 | t.Log(path) |
| 40 | 40 | ||
| 41 | path, err = LookFile(noExistedFile, ".") | 41 | path, err = SearchFile(noExistedFile, ".") |
| 42 | if err == nil { | 42 | if err == nil { |
| 43 | t.Errorf("err shouldnot be nil, got path: %s", SelfDir()) | 43 | t.Errorf("err shouldnot be nil, got path: %s", SelfDir()) |
| 44 | } | 44 | } | ... | ... |
-
Please register or sign in to post a comment