mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 08:40:54 +00:00
golint utils
This commit is contained in:
parent
5015614fdc
commit
c6448727de
@ -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()
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user