From c6448727de1442363444a628de5f7f3cf54af8db Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 14 Sep 2015 23:35:13 +0800 Subject: [PATCH] golint utils --- utils/caller.go | 2 +- utils/debug.go | 8 ++++---- utils/file.go | 4 ++-- utils/mail.go | 5 +++-- utils/safemap.go | 5 +++-- utils/slice.go | 2 +- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/utils/caller.go b/utils/caller.go index de04d96e..73c52a62 100644 --- a/utils/caller.go +++ b/utils/caller.go @@ -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() } diff --git a/utils/debug.go b/utils/debug.go index f9a682d3..2462e980 100644 --- a/utils/debug.go +++ b/utils/debug.go @@ -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 } diff --git a/utils/file.go b/utils/file.go index c9c3e903..db197882 100644 --- a/utils/file.go +++ b/utils/file.go @@ -44,7 +44,7 @@ func FileExists(name string) bool { return true } -// Search a file in paths. +// SearchFile 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) { diff --git a/utils/mail.go b/utils/mail.go index 4959268c..c8ba3d92 100644 --- a/utils/mail.go +++ b/utils/mail.go @@ -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 +// AttachFile Add 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) diff --git a/utils/safemap.go b/utils/safemap.go index 37e76eb3..2e438f2c 100644 --- a/utils/safemap.go +++ b/utils/safemap.go @@ -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() diff --git a/utils/slice.go b/utils/slice.go index e413004d..8f2cef98 100644 --- a/utils/slice.go +++ b/utils/slice.go @@ -116,7 +116,7 @@ func SliceIntersect(slice1, slice2 []interface{}) (diffslice []interface{}) { return } -// SliceChuck separates one slice to some sized slice. +// SliceChunk separates one slice to some sized slice. func SliceChunk(slice []interface{}, size int) (chunkslice [][]interface{}) { if size >= len(slice) { chunkslice = append(chunkslice, slice)