mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 13:40:55 +00:00
rename some function name under /utils
change the function name to common english word
This commit is contained in:
parent
3c92cce9f4
commit
9ff937591b
@ -30,7 +30,7 @@ func FileExists(name string) bool {
|
|||||||
|
|
||||||
// search a file in paths.
|
// search a file in paths.
|
||||||
// this is offen used in search config file in /etc ~/
|
// this is offen used in search config file in /etc ~/
|
||||||
func LookFile(filename string, paths ...string) (fullpath string, err error) {
|
func SearchFile(filename string, paths ...string) (fullpath string, err error) {
|
||||||
for _, path := range paths {
|
for _, path := range paths {
|
||||||
if fullpath = filepath.Join(path, filename); FileExists(fullpath) {
|
if fullpath = filepath.Join(path, filename); FileExists(fullpath) {
|
||||||
return
|
return
|
||||||
@ -41,7 +41,7 @@ func LookFile(filename string, paths ...string) (fullpath string, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// like command grep -E
|
// like command grep -E
|
||||||
// for example: GrepE(`^hello`, "hello.txt")
|
// for example: GrepFile(`^hello`, "hello.txt")
|
||||||
// \n is striped while read
|
// \n is striped while read
|
||||||
func GrepFile(patten string, filename string) (lines []string, err error) {
|
func GrepFile(patten string, filename string) (lines []string, err error) {
|
||||||
re, err := regexp.Compile(patten)
|
re, err := regexp.Compile(patten)
|
||||||
|
@ -23,7 +23,7 @@ func TestSelfDir(t *testing.T) {
|
|||||||
|
|
||||||
func TestFileExists(t *testing.T) {
|
func TestFileExists(t *testing.T) {
|
||||||
if !FileExists("./file.go") {
|
if !FileExists("./file.go") {
|
||||||
t.Errorf("/bin/echo should exists, but it didn't")
|
t.Errorf("./file.go should exists, but it didn't")
|
||||||
}
|
}
|
||||||
|
|
||||||
if FileExists(noExistedFile) {
|
if FileExists(noExistedFile) {
|
||||||
@ -31,14 +31,14 @@ func TestFileExists(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookFile(t *testing.T) {
|
func TestSearchFile(t *testing.T) {
|
||||||
path, err := LookFile(filepath.Base(SelfPath()), SelfDir())
|
path, err := SearchFile(filepath.Base(SelfPath()), SelfDir())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
t.Log(path)
|
t.Log(path)
|
||||||
|
|
||||||
path, err = LookFile(noExistedFile, ".")
|
path, err = SearchFile(noExistedFile, ".")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("err shouldnot be nil, got path: %s", SelfDir())
|
t.Errorf("err shouldnot be nil, got path: %s", SelfDir())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user