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
a43a1be0
Commit
a43a1be0
authored
Dec 11, 2013
by
skyblue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add some useful func
parent
52ebaece
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
5 deletions
+29
-5
caller.go
utils/caller.go
+10
-0
caller_test.go
utils/caller_test.go
+14
-0
file.go
utils/file.go
+1
-1
file_test.go
utils/file_test.go
+4
-4
No files found.
utils/caller.go
0 → 100644
View file @
a43a1be0
package
utils
import
(
"reflect"
"runtime"
)
func
GetFuncName
(
i
interface
{})
string
{
return
runtime
.
FuncForPC
(
reflect
.
ValueOf
(
i
)
.
Pointer
())
.
Name
()
}
utils/caller_test.go
0 → 100644
View file @
a43a1be0
package
utils
import
(
"strings"
"testing"
)
func
TestGetFuncName
(
t
*
testing
.
T
)
{
name
:=
GetFuncName
(
TestGetFuncName
)
t
.
Log
(
name
)
if
!
strings
.
HasSuffix
(
name
,
".TestGetFuncName"
)
{
t
.
Error
(
"get func name error"
)
}
}
utils/file.go
View file @
a43a1be0
...
...
@@ -43,7 +43,7 @@ func LookFile(filename string, paths ...string) (fullpath string, err error) {
// like command grep -E
// for example: GrepE(`^hello`, "hello.txt")
// \n is striped while read
func
Grep
E
(
patten
string
,
filename
string
)
(
lines
[]
string
,
err
error
)
{
func
Grep
File
(
patten
string
,
filename
string
)
(
lines
[]
string
,
err
error
)
{
re
,
err
:=
regexp
.
Compile
(
patten
)
if
err
!=
nil
{
return
...
...
utils/file_test.go
View file @
a43a1be0
...
...
@@ -22,7 +22,7 @@ func TestSelfDir(t *testing.T) {
}
func
TestFileExists
(
t
*
testing
.
T
)
{
if
!
FileExists
(
"
/bin/ech
o"
)
{
if
!
FileExists
(
"
./file.g
o"
)
{
t
.
Errorf
(
"/bin/echo should exists, but it didn't"
)
}
...
...
@@ -44,14 +44,14 @@ func TestLookFile(t *testing.T) {
}
}
func
TestGrep
E
(
t
*
testing
.
T
)
{
_
,
err
:=
Grep
E
(
""
,
noExistedFile
)
func
TestGrep
File
(
t
*
testing
.
T
)
{
_
,
err
:=
Grep
File
(
""
,
noExistedFile
)
if
err
==
nil
{
t
.
Error
(
"expect file-not-existed error, but got nothing"
)
}
path
:=
filepath
.
Join
(
"."
,
"testdata"
,
"grepe.test"
)
lines
,
err
:=
Grep
E
(
`^\s*[^#]+`
,
path
)
lines
,
err
:=
Grep
File
(
`^\s*[^#]+`
,
path
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
...
...
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