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
c6448727
Commit
c6448727
authored
Sep 14, 2015
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
golint utils
parent
5015614f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
14 additions
and
12 deletions
+14
-12
caller.go
utils/caller.go
+1
-1
debug.go
utils/debug.go
+4
-4
file.go
utils/file.go
+2
-2
mail.go
utils/mail.go
+3
-2
safemap.go
utils/safemap.go
+3
-2
slice.go
utils/slice.go
+1
-1
No files found.
utils/caller.go
View file @
c6448727
...
...
@@ -19,7 +19,7 @@ import (
"runtime"
)
// get function name
//
GetFuncName
get function name
func
GetFuncName
(
i
interface
{})
string
{
return
runtime
.
FuncForPC
(
reflect
.
ValueOf
(
i
)
.
Pointer
())
.
Name
()
}
utils/debug.go
View file @
c6448727
...
...
@@ -42,12 +42,12 @@ type pointerInfo struct {
used
[]
int
}
// print the data in console
//
Display
print the data in console
func
Display
(
data
...
interface
{})
{
display
(
true
,
data
...
)
}
// return data print string
//
GetDisplayString
return data print string
func
GetDisplayString
(
data
...
interface
{})
string
{
return
display
(
false
,
data
...
)
}
...
...
@@ -91,7 +91,7 @@ func fomateinfo(headlen int, data ...interface{}) []byte {
for
k
,
v
:=
range
data
{
var
buf2
=
new
(
bytes
.
Buffer
)
var
pointers
*
pointerInfo
var
interfaces
[]
reflect
.
Value
=
make
([]
reflect
.
Value
,
0
,
10
)
var
interfaces
=
make
([]
reflect
.
Value
,
0
,
10
)
printKeyValue
(
buf2
,
reflect
.
ValueOf
(
v
),
&
pointers
,
&
interfaces
,
nil
,
true
,
" "
,
1
)
...
...
@@ -385,7 +385,7 @@ func printPointerInfo(buf *bytes.Buffer, headlen int, pointers *pointerInfo) {
if
len
(
p
.
used
)
>
0
{
anyused
=
true
}
pointerNum
+=
1
pointerNum
++
p
.
n
=
pointerNum
}
...
...
utils/file.go
View file @
c6448727
...
...
@@ -44,7 +44,7 @@ func FileExists(name string) bool {
return
true
}
// Search a file in paths.
// Search
File Search
a file in paths.
// this is often used in search config file in /etc ~/
func
SearchFile
(
filename
string
,
paths
...
string
)
(
fullpath
string
,
err
error
)
{
for
_
,
path
:=
range
paths
{
...
...
@@ -56,7 +56,7 @@ func SearchFile(filename string, paths ...string) (fullpath string, err error) {
return
}
// like command grep -E
//
GrepFile
like command grep -E
// for example: GrepFile(`^hello`, "hello.txt")
// \n is striped while read
func
GrepFile
(
patten
string
,
filename
string
)
(
lines
[]
string
,
err
error
)
{
...
...
utils/mail.go
View file @
c6448727
...
...
@@ -80,7 +80,7 @@ func NewEMail(config string) *Email {
return
e
}
// Make all send information to byte
//
Bytes
Make all send information to byte
func
(
e
*
Email
)
Bytes
()
([]
byte
,
error
)
{
buff
:=
&
bytes
.
Buffer
{}
w
:=
multipart
.
NewWriter
(
buff
)
...
...
@@ -156,7 +156,7 @@ func (e *Email) Bytes() ([]byte, error) {
return
buff
.
Bytes
(),
nil
}
// Add attach file to the send mail
// A
ttachFile A
dd attach file to the send mail
func
(
e
*
Email
)
AttachFile
(
args
...
string
)
(
a
*
Attachment
,
err
error
)
{
if
len
(
args
)
<
1
&&
len
(
args
)
>
2
{
err
=
errors
.
New
(
"Must specify a file name and number of parameters can not exceed at least two"
)
...
...
@@ -215,6 +215,7 @@ func (e *Email) Attach(r io.Reader, filename string, args ...string) (a *Attachm
return
at
,
nil
}
// Send will send out the mail
func
(
e
*
Email
)
Send
()
error
{
if
e
.
Auth
==
nil
{
e
.
Auth
=
smtp
.
PlainAuth
(
e
.
Identity
,
e
.
Username
,
e
.
Password
,
e
.
Host
)
...
...
utils/safemap.go
View file @
c6448727
...
...
@@ -18,6 +18,7 @@ import (
"sync"
)
// BeeMap is a map with lock
type
BeeMap
struct
{
lock
*
sync
.
RWMutex
bm
map
[
interface
{}]
interface
{}
...
...
@@ -41,7 +42,7 @@ func (m *BeeMap) Get(k interface{}) interface{} {
return
nil
}
// Maps the given key and value. Returns false
//
Set
Maps the given key and value. Returns false
// if the key is already in the map and changes nothing.
func
(
m
*
BeeMap
)
Set
(
k
interface
{},
v
interface
{})
bool
{
m
.
lock
.
Lock
()
...
...
@@ -56,7 +57,7 @@ func (m *BeeMap) Set(k interface{}, v interface{}) bool {
return
true
}
// Returns true if k is exist in the map.
//
Check
Returns true if k is exist in the map.
func
(
m
*
BeeMap
)
Check
(
k
interface
{})
bool
{
m
.
lock
.
RLock
()
defer
m
.
lock
.
RUnlock
()
...
...
utils/slice.go
View file @
c6448727
...
...
@@ -116,7 +116,7 @@ func SliceIntersect(slice1, slice2 []interface{}) (diffslice []interface{}) {
return
}
// SliceChu
c
k separates one slice to some sized slice.
// SliceChu
n
k separates one slice to some sized slice.
func
SliceChunk
(
slice
[]
interface
{},
size
int
)
(
chunkslice
[][]
interface
{})
{
if
size
>=
len
(
slice
)
{
chunkslice
=
append
(
chunkslice
,
slice
)
...
...
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