From 9b2597be6842d97756758ffaa48535377d63ab26 Mon Sep 17 00:00:00 2001 From: astaxie Date: Sun, 17 Jan 2016 23:48:09 +0800 Subject: [PATCH 1/3] fix the mail send empty subject --- utils/mail.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/utils/mail.go b/utils/mail.go index ffaafd4c..2270b553 100644 --- a/utils/mail.go +++ b/utils/mail.go @@ -96,12 +96,16 @@ func (e *Email) Bytes() ([]byte, error) { e.Headers.Set("Disposition-Notification-To", strings.Join(e.ReadReceipt, ",")) } e.Headers.Set("MIME-Version", "1.0") - e.Headers.Set("Content-Type", fmt.Sprintf("multipart/mixed;\r\n boundary=%s\r\n", w.Boundary())) // Write the envelope headers (including any custom headers) if err := headerToBytes(buff, e.Headers); err != nil { return nil, fmt.Errorf("Failed to render message headers: %s", err) } + + e.Headers.Set("Content-Type", fmt.Sprintf("multipart/mixed;\r\n boundary=%s\r\n", w.Boundary())) + fmt.Fprintf(w, "%s:", "Content-Type") + fmt.Fprintf(w, " %s\r\n", fmt.Sprintf("multipart/mixed;\r\n boundary=%s\r\n", w.Boundary())) + // Start the multipart/mixed part fmt.Fprintf(buff, "--%s\r\n", w.Boundary()) header := textproto.MIMEHeader{} From 90d1349665028c617db620644e31f8a999f42ed7 Mon Sep 17 00:00:00 2001 From: astaxie Date: Sun, 17 Jan 2016 23:48:17 +0800 Subject: [PATCH 2/3] fix typo --- config/json.go | 2 +- doc.go | 2 +- orm/orm_conds.go | 2 +- orm/qb_mysql.go | 2 +- plugins/apiauth/apiauth.go | 2 +- session/sess_cookie_test.go | 4 ++-- template.go | 2 +- templatefunc.go | 2 +- utils/captcha/captcha.go | 4 ++-- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/config/json.go b/config/json.go index 6929baad..65b4ac48 100644 --- a/config/json.go +++ b/config/json.go @@ -164,7 +164,7 @@ func (c *JSONConfigContainer) String(key string) string { // DefaultString returns the string value for a given key. // if err != nil return defaltval func (c *JSONConfigContainer) DefaultString(key string, defaultval string) string { - // TODO FIXME should not use "" to replace non existance + // TODO FIXME should not use "" to replace non existence if v := c.String(key); v != "" { return v } diff --git a/doc.go b/doc.go index 4be305b3..8825bd29 100644 --- a/doc.go +++ b/doc.go @@ -12,6 +12,6 @@ beego is inspired by Tornado, Sinatra and Flask with the added benefit of some G beego.Run() } -more infomation: http://beego.me +more information: http://beego.me */ package beego diff --git a/orm/orm_conds.go b/orm/orm_conds.go index b2eae418..e56d6fbb 100644 --- a/orm/orm_conds.go +++ b/orm/orm_conds.go @@ -19,7 +19,7 @@ import ( "strings" ) -// ExprSep define the expression seperation +// ExprSep define the expression separation const ( ExprSep = "__" ) diff --git a/orm/qb_mysql.go b/orm/qb_mysql.go index f6d1e185..886bc50e 100644 --- a/orm/qb_mysql.go +++ b/orm/qb_mysql.go @@ -20,7 +20,7 @@ import ( "strings" ) -// CommaSpace is the seperation +// CommaSpace is the separation const CommaSpace = ", " // MySQLQueryBuilder is the SQL build diff --git a/plugins/apiauth/apiauth.go b/plugins/apiauth/apiauth.go index 3091c698..8af08088 100644 --- a/plugins/apiauth/apiauth.go +++ b/plugins/apiauth/apiauth.go @@ -41,7 +41,7 @@ // // 1. appid // -// appid is asigned to the application +// appid is assigned to the application // // 2. signature // diff --git a/session/sess_cookie_test.go b/session/sess_cookie_test.go index b5982260..209e501c 100644 --- a/session/sess_cookie_test.go +++ b/session/sess_cookie_test.go @@ -80,7 +80,7 @@ func TestDestorySessionCookie(t *testing.T) { t.Fatal("get cookie session id is not the same again.") } - // After destory session , will get a new session id . + // After destroy session , will get a new session id . globalSessions.SessionDestroy(w, r1) r2, _ := http.NewRequest("GET", "/", nil) r2.Header.Set("Cookie", w.Header().Get("Set-Cookie")) @@ -91,6 +91,6 @@ func TestDestorySessionCookie(t *testing.T) { t.Fatal("session start error") } if newSession.SessionID() == session.SessionID() { - t.Fatal("after destory session and reqeust again ,get cookie session id is same.") + t.Fatal("after destroy session and reqeust again ,get cookie session id is same.") } } diff --git a/template.go b/template.go index 9aac3ea2..0ff2eea0 100644 --- a/template.go +++ b/template.go @@ -31,7 +31,7 @@ var ( beegoTplFuncMap = make(template.FuncMap) // BeeTemplates caching map and supported template file extensions. BeeTemplates = make(map[string]*template.Template) - // BeeTemplateExt stores the template extention which will build + // BeeTemplateExt stores the template extension which will build BeeTemplateExt = []string{"tpl", "html"} ) diff --git a/templatefunc.go b/templatefunc.go index e944bc73..bc265321 100644 --- a/templatefunc.go +++ b/templatefunc.go @@ -670,7 +670,7 @@ func MapGet(arg1 interface{}, arg2 ...interface{}) (interface{}, error) { if arg1Type.Kind() == reflect.Map && len(arg2) > 0 { // check whether arg2[0] type equals to arg1 key type - // if they are different, make convertion + // if they are different, make conversion arg2Val := reflect.ValueOf(arg2[0]) arg2Type := reflect.TypeOf(arg2[0]) if arg2Type.Kind() != arg1Type.Key().Kind() { diff --git a/utils/captcha/captcha.go b/utils/captcha/captcha.go index 4ac5c9f9..31098f9a 100644 --- a/utils/captcha/captcha.go +++ b/utils/captcha/captcha.go @@ -158,7 +158,7 @@ func (c *Captcha) Handler(ctx *context.Context) { } } -// CreateCaptchaHTML tempalte func for output html +// CreateCaptchaHTML template func for output html func (c *Captcha) CreateCaptchaHTML() template.HTML { value, err := c.CreateCaptcha() if err != nil { @@ -255,7 +255,7 @@ func NewCaptcha(urlPrefix string, store cache.Cache) *Captcha { } // NewWithFilter create a new captcha.Captcha and auto AddFilter for serve captacha image -// and add a tempalte func for output html +// and add a template func for output html func NewWithFilter(urlPrefix string, store cache.Cache) *Captcha { cpt := NewCaptcha(urlPrefix, store) From 9adf20d72ea1c6db2adbe2fcd64cb4ff4219272f Mon Sep 17 00:00:00 2001 From: astaxie Date: Sun, 17 Jan 2016 23:57:07 +0800 Subject: [PATCH 3/3] gofmt -s --- cache/file.go | 8 ++++---- cache/memcache/memcache.go | 5 +++-- cache/memory.go | 6 +++--- context/acceptencoder_test.go | 15 +++++++-------- grace/grace.go | 16 ++++++++-------- logs/console_test.go | 1 - logs/file_test.go | 3 +-- swagger/docs_spec.go | 4 ++-- tree.go | 4 ++-- 9 files changed, 30 insertions(+), 32 deletions(-) diff --git a/cache/file.go b/cache/file.go index 3a7aa8b0..e2ba70e3 100644 --- a/cache/file.go +++ b/cache/file.go @@ -39,10 +39,10 @@ type FileCacheItem struct { // FileCache Config var ( - FileCachePath = "cache" // cache directory - FileCacheFileSuffix = ".bin" // cache file suffix - FileCacheDirectoryLevel = 2 // cache file deep level if auto generated cache files. - FileCacheEmbedExpiry time.Duration = 0 // cache expire time, default is no expire forever. + FileCachePath = "cache" // cache directory + FileCacheFileSuffix = ".bin" // cache file suffix + FileCacheDirectoryLevel = 2 // cache file deep level if auto generated cache files. + FileCacheEmbedExpiry time.Duration = 0 // cache expire time, default is no expire forever. ) // FileCache is cache adapter for file storage. diff --git a/cache/memcache/memcache.go b/cache/memcache/memcache.go index 15ea5d3e..3f0fe411 100644 --- a/cache/memcache/memcache.go +++ b/cache/memcache/memcache.go @@ -36,8 +36,9 @@ import ( "github.com/bradfitz/gomemcache/memcache" - "github.com/astaxie/beego/cache" "time" + + "github.com/astaxie/beego/cache" ) // Cache Memcache adapter. @@ -100,7 +101,7 @@ func (rc *Cache) Put(key string, val interface{}, timeout time.Duration) error { if !ok { return errors.New("val must string") } - item := memcache.Item{Key: key, Value: []byte(v), Expiration: int32(timeout/time.Second)} + item := memcache.Item{Key: key, Value: []byte(v), Expiration: int32(timeout / time.Second)} return rc.conn.Set(&item) } diff --git a/cache/memory.go b/cache/memory.go index d928afdb..fff2ebbb 100644 --- a/cache/memory.go +++ b/cache/memory.go @@ -86,9 +86,9 @@ func (bc *MemoryCache) Put(name string, value interface{}, lifespan time.Duratio bc.Lock() defer bc.Unlock() bc.items[name] = &MemoryItem{ - val: value, + val: value, createdTime: time.Now(), - lifespan: lifespan, + lifespan: lifespan, } return nil } @@ -200,7 +200,7 @@ func (bc *MemoryCache) StartAndGC(config string) error { cf = make(map[string]int) cf["interval"] = DefaultEvery } - dur := time.Duration(cf["interval"]) * time.Second + dur := time.Duration(cf["interval"]) * time.Second bc.Every = cf["interval"] bc.dur = dur go bc.vaccuum() diff --git a/context/acceptencoder_test.go b/context/acceptencoder_test.go index 147313c5..3afff679 100644 --- a/context/acceptencoder_test.go +++ b/context/acceptencoder_test.go @@ -20,26 +20,25 @@ import ( ) func Test_ExtractEncoding(t *testing.T) { - if parseEncoding(&http.Request{Header: map[string][]string{"Accept-Encoding": []string{"gzip,deflate"}}}) != "gzip" { + if parseEncoding(&http.Request{Header: map[string][]string{"Accept-Encoding": {"gzip,deflate"}}}) != "gzip" { t.Fail() } - if parseEncoding(&http.Request{Header: map[string][]string{"Accept-Encoding": []string{"deflate,gzip"}}}) != "deflate" { + if parseEncoding(&http.Request{Header: map[string][]string{"Accept-Encoding": {"deflate,gzip"}}}) != "deflate" { t.Fail() } - if parseEncoding(&http.Request{Header: map[string][]string{"Accept-Encoding": []string{"gzip;q=.5,deflate"}}}) != "deflate" { + if parseEncoding(&http.Request{Header: map[string][]string{"Accept-Encoding": {"gzip;q=.5,deflate"}}}) != "deflate" { t.Fail() } - if parseEncoding(&http.Request{Header: map[string][]string{"Accept-Encoding": []string{"gzip;q=.5,deflate;q=0.3"}}}) != "gzip" { + if parseEncoding(&http.Request{Header: map[string][]string{"Accept-Encoding": {"gzip;q=.5,deflate;q=0.3"}}}) != "gzip" { t.Fail() } - - if parseEncoding(&http.Request{Header: map[string][]string{"Accept-Encoding": []string{"gzip;q=0,deflate"}}}) != "deflate" { + if parseEncoding(&http.Request{Header: map[string][]string{"Accept-Encoding": {"gzip;q=0,deflate"}}}) != "deflate" { t.Fail() } - if parseEncoding(&http.Request{Header: map[string][]string{"Accept-Encoding": []string{"deflate;q=0.5,gzip;q=0.5,identity"}}}) != "" { + if parseEncoding(&http.Request{Header: map[string][]string{"Accept-Encoding": {"deflate;q=0.5,gzip;q=0.5,identity"}}}) != "" { t.Fail() } - if parseEncoding(&http.Request{Header: map[string][]string{"Accept-Encoding": []string{"*"}}}) != "gzip" { + if parseEncoding(&http.Request{Header: map[string][]string{"Accept-Encoding": {"*"}}}) != "gzip" { t.Fail() } } diff --git a/grace/grace.go b/grace/grace.go index af530d50..af4e9068 100644 --- a/grace/grace.go +++ b/grace/grace.go @@ -118,15 +118,15 @@ func NewServer(addr string, handler http.Handler) (srv *Server) { sigChan: make(chan os.Signal), isChild: isChild, SignalHooks: map[int]map[os.Signal][]func(){ - PreSignal: map[os.Signal][]func(){ - syscall.SIGHUP: []func(){}, - syscall.SIGINT: []func(){}, - syscall.SIGTERM: []func(){}, + PreSignal: { + syscall.SIGHUP: {}, + syscall.SIGINT: {}, + syscall.SIGTERM: {}, }, - PostSignal: map[os.Signal][]func(){ - syscall.SIGHUP: []func(){}, - syscall.SIGINT: []func(){}, - syscall.SIGTERM: []func(){}, + PostSignal: { + syscall.SIGHUP: {}, + syscall.SIGINT: {}, + syscall.SIGTERM: {}, }, }, state: StateInit, diff --git a/logs/console_test.go b/logs/console_test.go index c4bb1da2..ce8937d4 100644 --- a/logs/console_test.go +++ b/logs/console_test.go @@ -42,4 +42,3 @@ func TestConsole(t *testing.T) { log2.SetLogger("console", `{"level":3}`) testConsoleCalls(log2) } - diff --git a/logs/file_test.go b/logs/file_test.go index f9b54c26..1fa6cdaa 100644 --- a/logs/file_test.go +++ b/logs/file_test.go @@ -130,7 +130,6 @@ func BenchmarkFile(b *testing.B) { os.Remove("test4.log") } - func BenchmarkFileAsynchronous(b *testing.B) { log := NewLogger(100000) log.SetLogger("file", `{"filename":"test4.log"}`) @@ -168,7 +167,7 @@ func BenchmarkFileOnGoroutine(b *testing.B) { log := NewLogger(100000) log.SetLogger("file", `{"filename":"test4.log"}`) for i := 0; i < b.N; i++ { - go log.Debug("debug") + go log.Debug("debug") } os.Remove("test4.log") } diff --git a/swagger/docs_spec.go b/swagger/docs_spec.go index d8402aa5..680324dc 100644 --- a/swagger/docs_spec.go +++ b/swagger/docs_spec.go @@ -23,8 +23,8 @@ type ResourceListing struct { APIVersion string `json:"apiVersion"` SwaggerVersion string `json:"swaggerVersion"` // e.g 1.2 // BasePath string `json:"basePath"` obsolete in 1.1 - APIs []APIRef `json:"apis"` - Info Information `json:"info"` + APIs []APIRef `json:"apis"` + Info Information `json:"info"` } // APIRef description the api path and description diff --git a/tree.go b/tree.go index 70321d67..a6ffe062 100644 --- a/tree.go +++ b/tree.go @@ -141,7 +141,7 @@ func (t *Tree) addtree(segments []string, tree *Tree, wildcards []string, reg st regexpStr = "([^.]+).(.+)" params = params[1:] } else { - for _ = range params { + for range params { regexpStr = "([^/]+)/" + regexpStr } } @@ -254,7 +254,7 @@ func (t *Tree) addseg(segments []string, route interface{}, wildcards []string, regexpStr = "/([^.]+).(.+)" params = params[1:] } else { - for _ = range params { + for range params { regexpStr = "/([^/]+)" + regexpStr } }