From d79c2978805a370616c60f0f1d1284bcddc2fa97 Mon Sep 17 00:00:00 2001 From: slene Date: Mon, 17 Mar 2014 12:27:04 +0800 Subject: [PATCH 01/10] rollback: set httponly default is false. --- context/output.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/context/output.go b/context/output.go index a8a304b6..2d7814e4 100644 --- a/context/output.go +++ b/context/output.go @@ -135,12 +135,12 @@ func (output *BeegoOutput) Cookie(name string, value string, others ...interface } } - // default true - httponly := true + // default false. for session cookie default true + httponly := false if len(others) > 4 { - if v, ok := others[4].(bool); ok && !v || others[4] == nil { - // HttpOnly = false - httponly = false + if v, ok := others[4].(bool); ok && v { + // HttpOnly = true + httponly = true } } From ff1938054a3fe149540086f3941c97a84678a3ac Mon Sep 17 00:00:00 2001 From: "asta.xie" Date: Fri, 21 Mar 2014 14:07:03 +0800 Subject: [PATCH 02/10] add w.Rotate --- logs/file.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/logs/file.go b/logs/file.go index d0512e26..d61136c0 100644 --- a/logs/file.go +++ b/logs/file.go @@ -118,9 +118,9 @@ func (w *FileLogWriter) StartLogger() error { func (w *FileLogWriter) docheck(size int) { w.startLock.Lock() defer w.startLock.Unlock() - if (w.Maxlines > 0 && w.maxlines_curlines >= w.Maxlines) || + if w.Rotate && ((w.Maxlines > 0 && w.maxlines_curlines >= w.Maxlines) || (w.Maxsize > 0 && w.maxsize_cursize >= w.Maxsize) || - (w.Daily && time.Now().Day() != w.daily_opendate) { + (w.Daily && time.Now().Day() != w.daily_opendate)) { if err := w.DoRotate(); err != nil { fmt.Fprintf(os.Stderr, "FileLogWriter(%q): %s\n", w.Filename, err) return From 443aaadcced2cefb447dba467220a8f5662ae580 Mon Sep 17 00:00:00 2001 From: "asta.xie" Date: Fri, 21 Mar 2014 14:24:00 +0800 Subject: [PATCH 03/10] fix #533 change the function name --- session/session.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/session/session.go b/session/session.go index bc8832b0..7da0d41f 100644 --- a/session/session.go +++ b/session/session.go @@ -173,7 +173,7 @@ func (manager *Manager) SessionDestroy(w http.ResponseWriter, r *http.Request) { } // Get SessionStore by its id. -func (manager *Manager) GetProvider(sid string) (sessions SessionStore, err error) { +func (manager *Manager) GetSessionStore(sid string) (sessions SessionStore, err error) { sessions, err = manager.provider.SessionRead(sid) return } From 9421a2103700233447cf1cb4c11bff63e3d3da61 Mon Sep 17 00:00:00 2001 From: slene Date: Fri, 4 Apr 2014 07:33:13 +0800 Subject: [PATCH 04/10] beego: fix log output when SetLogger has error --- logs/console.go | 3 +++ logs/log.go | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/logs/console.go b/logs/console.go index 438facfe..6af6aa16 100644 --- a/logs/console.go +++ b/logs/console.go @@ -43,6 +43,9 @@ func NewConsole() LoggerInterface { // init console logger. // jsonconfig like '{"level":LevelTrace}'. func (c *ConsoleWriter) Init(jsonconfig string) error { + if len(jsonconfig) == 0 { + return nil + } err := json.Unmarshal([]byte(jsonconfig), c) if err != nil { return err diff --git a/logs/log.go b/logs/log.go index c859c1e6..025da55c 100644 --- a/logs/log.go +++ b/logs/log.go @@ -79,14 +79,15 @@ func (bl *BeeLogger) SetLogger(adaptername string, config string) error { if log, ok := adapters[adaptername]; ok { lg := log() err := lg.Init(config) + bl.outputs[adaptername] = lg if err != nil { + fmt.Println("logs.BeeLogger.SetLogger: " + err.Error()) return err } - bl.outputs[adaptername] = lg - return nil } else { return fmt.Errorf("logs: unknown adaptername %q (forgotten Register?)", adaptername) } + return nil } // remove a logger adapter in BeeLogger. From f48ca96a7eb6fda8566457be341cc1c52c33cc54 Mon Sep 17 00:00:00 2001 From: slene Date: Fri, 4 Apr 2014 07:33:13 +0800 Subject: [PATCH 05/10] beego: fix log output when SetLogger has error --- logs/conn.go | 3 +++ logs/file.go | 3 +++ logs/smtp.go | 3 +++ 3 files changed, 9 insertions(+) diff --git a/logs/conn.go b/logs/conn.go index eed9ae2f..77bf4de8 100644 --- a/logs/conn.go +++ b/logs/conn.go @@ -29,6 +29,9 @@ func NewConn() LoggerInterface { // init connection writer with json config. // json config only need key "level". func (c *ConnWriter) Init(jsonconfig string) error { + if len(jsonconfig) == 0 { + return nil + } err := json.Unmarshal([]byte(jsonconfig), c) if err != nil { return err diff --git a/logs/file.go b/logs/file.go index 9400e04d..c9f81df5 100644 --- a/logs/file.go +++ b/logs/file.go @@ -90,6 +90,9 @@ func NewFileWriter() LoggerInterface { // "rotate":true // } func (w *FileLogWriter) Init(jsonconfig string) error { + if len(jsonconfig) == 0 { + return nil + } err := json.Unmarshal([]byte(jsonconfig), w) if err != nil { return err diff --git a/logs/smtp.go b/logs/smtp.go index 19296887..ec1c61ca 100644 --- a/logs/smtp.go +++ b/logs/smtp.go @@ -38,6 +38,9 @@ func NewSmtpWriter() LoggerInterface { // "level":LevelError // } func (s *SmtpWriter) Init(jsonconfig string) error { + if len(jsonconfig) == 0 { + return nil + } err := json.Unmarshal([]byte(jsonconfig), s) if err != nil { return err From 3f1de576e425fc914a5cd1a1a828f298f2694934 Mon Sep 17 00:00:00 2001 From: astaxie Date: Fri, 4 Apr 2014 09:49:55 +0800 Subject: [PATCH 06/10] fix go run hello.go & console log --- beego.go | 2 +- config.go | 8 ++++++-- logs/conn.go | 3 --- logs/file.go | 3 --- logs/smtp.go | 3 --- 5 files changed, 7 insertions(+), 12 deletions(-) diff --git a/beego.go b/beego.go index 52b2ef92..112ecd4b 100644 --- a/beego.go +++ b/beego.go @@ -188,7 +188,7 @@ func initBeforeHttpRun() { // if AppConfigPath not In the conf/app.conf reParse config if AppConfigPath != filepath.Join(AppPath, "conf", "app.conf") { err := ParseConfig() - if err != nil { + if err != nil && AppConfigPath != filepath.Join(workPath, "conf", "app.conf") { // configuration is critical to app, panic here if parse failed panic(err) } diff --git a/config.go b/config.go index a963ac02..6abc1b68 100644 --- a/config.go +++ b/config.go @@ -1,6 +1,7 @@ package beego import ( + "fmt" "html/template" "os" "path/filepath" @@ -143,9 +144,12 @@ func init() { // init BeeLogger BeeLogger = logs.NewLogger(10000) - BeeLogger.SetLogger("console", "") + err := BeeLogger.SetLogger("console", "") + if err != nil { + fmt.Println("init console log error:", err) + } - err := ParseConfig() + err = ParseConfig() if err != nil && !os.IsNotExist(err) { // for init if doesn't have app.conf will not panic Info(err) diff --git a/logs/conn.go b/logs/conn.go index 77bf4de8..eed9ae2f 100644 --- a/logs/conn.go +++ b/logs/conn.go @@ -29,9 +29,6 @@ func NewConn() LoggerInterface { // init connection writer with json config. // json config only need key "level". func (c *ConnWriter) Init(jsonconfig string) error { - if len(jsonconfig) == 0 { - return nil - } err := json.Unmarshal([]byte(jsonconfig), c) if err != nil { return err diff --git a/logs/file.go b/logs/file.go index c9f81df5..9400e04d 100644 --- a/logs/file.go +++ b/logs/file.go @@ -90,9 +90,6 @@ func NewFileWriter() LoggerInterface { // "rotate":true // } func (w *FileLogWriter) Init(jsonconfig string) error { - if len(jsonconfig) == 0 { - return nil - } err := json.Unmarshal([]byte(jsonconfig), w) if err != nil { return err diff --git a/logs/smtp.go b/logs/smtp.go index ec1c61ca..19296887 100644 --- a/logs/smtp.go +++ b/logs/smtp.go @@ -38,9 +38,6 @@ func NewSmtpWriter() LoggerInterface { // "level":LevelError // } func (s *SmtpWriter) Init(jsonconfig string) error { - if len(jsonconfig) == 0 { - return nil - } err := json.Unmarshal([]byte(jsonconfig), s) if err != nil { return err From f222f5b2381ff1eb809a02bfb0403cd0b4101ceb Mon Sep 17 00:00:00 2001 From: astaxie Date: Fri, 4 Apr 2014 09:56:25 +0800 Subject: [PATCH 07/10] beego: hot fix for console logs & go run can't find file. --- beego.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beego.go b/beego.go index 112ecd4b..6a727906 100644 --- a/beego.go +++ b/beego.go @@ -13,7 +13,7 @@ import ( ) // beego web framework version. -const VERSION = "1.1.2" +const VERSION = "1.1.3" type hookfunc func() error //hook function to run var hooks []hookfunc //hook function slice to store the hookfunc From 8cbea70e072048363b07a5457c6b920378e2cbbb Mon Sep 17 00:00:00 2001 From: astaxie Date: Fri, 4 Apr 2014 10:04:22 +0800 Subject: [PATCH 08/10] beego: hot fix for TestBeegoInit can't parsefile --- beego.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/beego.go b/beego.go index 6a727906..439add44 100644 --- a/beego.go +++ b/beego.go @@ -238,6 +238,11 @@ func initBeforeHttpRun() { func TestBeegoInit(apppath string) { AppPath = apppath AppConfigPath = filepath.Join(AppPath, "conf", "app.conf") + err := ParseConfig() + if err != nil && !os.IsNotExist(err) { + // for init if doesn't have app.conf will not panic + Info(err) + } os.Chdir(AppPath) initBeforeHttpRun() } From 18f70e6ee49c031de3bb6c0fe14148877713efcb Mon Sep 17 00:00:00 2001 From: Donald Zhan Date: Wed, 9 Apr 2014 12:39:12 +0800 Subject: [PATCH 09/10] update the error message --- cache/cache_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cache/cache_test.go b/cache/cache_test.go index bc484e0f..52612cfd 100644 --- a/cache/cache_test.go +++ b/cache/cache_test.go @@ -40,7 +40,7 @@ func TestCache(t *testing.T) { } if err = bm.Decr("astaxie"); err != nil { - t.Error("Incr Error", err) + t.Error("Decr Error", err) } if v := bm.Get("astaxie"); v.(int) != 1 { @@ -77,7 +77,7 @@ func TestFileCache(t *testing.T) { } if err = bm.Decr("astaxie"); err != nil { - t.Error("Incr Error", err) + t.Error("Decr Error", err) } if v := bm.Get("astaxie"); v.(int) != 1 { From 1bb876f2dfa4711858082cb888ddd5d986a3d95b Mon Sep 17 00:00:00 2001 From: Lin Luxiang Date: Tue, 8 Apr 2014 18:16:16 +0800 Subject: [PATCH 10/10] make Maxage work --- session/sess_cookie.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/session/sess_cookie.go b/session/sess_cookie.go index 54acba31..0fe7b093 100644 --- a/session/sess_cookie.go +++ b/session/sess_cookie.go @@ -73,7 +73,8 @@ func (st *CookieSessionStore) SessionRelease(w http.ResponseWriter) { Value: url.QueryEscape(str), Path: "/", HttpOnly: true, - Secure: cookiepder.config.Secure} + Secure: cookiepder.config.Secure, + MaxAge: cookiepder.config.Maxage} http.SetCookie(w, cookie) return }