Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
a43a1be0
authored
2013-12-11 22:18:45 +0800
by
skyblue
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
add some useful func
1 parent
52ebaece
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
5 deletions
utils/caller.go
utils/caller_test.go
utils/file.go
utils/file_test.go
utils/caller.go
0 → 100644
View file @
a43a1be
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 @
a43a1be
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 @
a43a1be
...
...
@@ -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 @
a43a1be
...
...
@@ -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
Styling with
Markdown
is supported
Attach a file
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 post a comment