1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-25 20:51:29 +00:00

golint utils

This commit is contained in:
astaxie 2015-09-14 23:35:13 +08:00
parent 5015614fdc
commit c6448727de
6 changed files with 14 additions and 12 deletions

View File

@ -19,7 +19,7 @@ import (
"runtime" "runtime"
) )
// get function name // GetFuncName get function name
func GetFuncName(i interface{}) string { func GetFuncName(i interface{}) string {
return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name() return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
} }

View File

@ -42,12 +42,12 @@ type pointerInfo struct {
used []int used []int
} }
// print the data in console // Display print the data in console
func Display(data ...interface{}) { func Display(data ...interface{}) {
display(true, data...) display(true, data...)
} }
// return data print string // GetDisplayString return data print string
func GetDisplayString(data ...interface{}) string { func GetDisplayString(data ...interface{}) string {
return display(false, data...) return display(false, data...)
} }
@ -91,7 +91,7 @@ func fomateinfo(headlen int, data ...interface{}) []byte {
for k, v := range data { for k, v := range data {
var buf2 = new(bytes.Buffer) var buf2 = new(bytes.Buffer)
var pointers *pointerInfo 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) 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 { if len(p.used) > 0 {
anyused = true anyused = true
} }
pointerNum += 1 pointerNum++
p.n = pointerNum p.n = pointerNum
} }

View File

@ -44,7 +44,7 @@ func FileExists(name string) bool {
return true return true
} }
// Search a file in paths. // SearchFile Search a file in paths.
// this is often used in search config file in /etc ~/ // this is often used in search config file in /etc ~/
func SearchFile(filename string, paths ...string) (fullpath string, err error) { func SearchFile(filename string, paths ...string) (fullpath string, err error) {
for _, path := range paths { for _, path := range paths {
@ -56,7 +56,7 @@ func SearchFile(filename string, paths ...string) (fullpath string, err error) {
return return
} }
// like command grep -E // GrepFile like command grep -E
// for example: GrepFile(`^hello`, "hello.txt") // for example: GrepFile(`^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) {

View File

@ -80,7 +80,7 @@ func NewEMail(config string) *Email {
return e return e
} }
// Make all send information to byte // Bytes Make all send information to byte
func (e *Email) Bytes() ([]byte, error) { func (e *Email) Bytes() ([]byte, error) {
buff := &bytes.Buffer{} buff := &bytes.Buffer{}
w := multipart.NewWriter(buff) w := multipart.NewWriter(buff)
@ -156,7 +156,7 @@ func (e *Email) Bytes() ([]byte, error) {
return buff.Bytes(), nil 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) { func (e *Email) AttachFile(args ...string) (a *Attachment, err error) {
if len(args) < 1 && len(args) > 2 { 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") 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 return at, nil
} }
// Send will send out the mail
func (e *Email) Send() error { func (e *Email) Send() error {
if e.Auth == nil { if e.Auth == nil {
e.Auth = smtp.PlainAuth(e.Identity, e.Username, e.Password, e.Host) e.Auth = smtp.PlainAuth(e.Identity, e.Username, e.Password, e.Host)

View File

@ -18,6 +18,7 @@ import (
"sync" "sync"
) )
// BeeMap is a map with lock
type BeeMap struct { type BeeMap struct {
lock *sync.RWMutex lock *sync.RWMutex
bm map[interface{}]interface{} bm map[interface{}]interface{}
@ -41,7 +42,7 @@ func (m *BeeMap) Get(k interface{}) interface{} {
return nil 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. // if the key is already in the map and changes nothing.
func (m *BeeMap) Set(k interface{}, v interface{}) bool { func (m *BeeMap) Set(k interface{}, v interface{}) bool {
m.lock.Lock() m.lock.Lock()
@ -56,7 +57,7 @@ func (m *BeeMap) Set(k interface{}, v interface{}) bool {
return true 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 { func (m *BeeMap) Check(k interface{}) bool {
m.lock.RLock() m.lock.RLock()
defer m.lock.RUnlock() defer m.lock.RUnlock()

View File

@ -116,7 +116,7 @@ func SliceIntersect(slice1, slice2 []interface{}) (diffslice []interface{}) {
return 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{}) { func SliceChunk(slice []interface{}, size int) (chunkslice [][]interface{}) {
if size >= len(slice) { if size >= len(slice) {
chunkslice = append(chunkslice, slice) chunkslice = append(chunkslice, slice)