Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
c8724d40
Commit
c8724d40
authored
Dec 12, 2013
by
astaxie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #362 from kyle-wang/master
rename some function name under /utils
parents
3c92cce9
9ff93759
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
6 deletions
+6
-6
file.go
utils/file.go
+2
-2
file_test.go
utils/file_test.go
+4
-4
No files found.
utils/file.go
View file @
c8724d40
...
@@ -30,7 +30,7 @@ func FileExists(name string) bool {
...
@@ -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
Look
File
(
filename
string
,
paths
...
string
)
(
fullpath
string
,
err
error
)
{
func
Search
File
(
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) {
...
@@ -41,7 +41,7 @@ func LookFile(filename string, paths ...string) (fullpath string, err error) {
}
}
// like command grep -E
// like command grep -E
// for example: Grep
E
(`^hello`, "hello.txt")
// for example: Grep
File
(`^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
)
...
...
utils/file_test.go
View file @
c8724d40
...
@@ -23,7 +23,7 @@ func TestSelfDir(t *testing.T) {
...
@@ -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/ech
o should exists, but it didn't"
)
t
.
Errorf
(
"
./file.g
o should exists, but it didn't"
)
}
}
if
FileExists
(
noExistedFile
)
{
if
FileExists
(
noExistedFile
)
{
...
@@ -31,14 +31,14 @@ func TestFileExists(t *testing.T) {
...
@@ -31,14 +31,14 @@ func TestFileExists(t *testing.T) {
}
}
}
}
func
Test
Look
File
(
t
*
testing
.
T
)
{
func
Test
Search
File
(
t
*
testing
.
T
)
{
path
,
err
:=
Look
File
(
filepath
.
Base
(
SelfPath
()),
SelfDir
())
path
,
err
:=
Search
File
(
filepath
.
Base
(
SelfPath
()),
SelfDir
())
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Error
(
err
)
t
.
Error
(
err
)
}
}
t
.
Log
(
path
)
t
.
Log
(
path
)
path
,
err
=
Look
File
(
noExistedFile
,
"."
)
path
,
err
=
Search
File
(
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
())
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment