From 5ba90258a45180c8123484aa52609213fce2a9e5 Mon Sep 17 00:00:00 2001 From: "Hank.Lu" Date: Thu, 6 Dec 2018 15:00:12 +0800 Subject: [PATCH 01/11] Update apiapp.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit db连接信息使用双引号包含 --- cmd/commands/api/apiapp.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/commands/api/apiapp.go b/cmd/commands/api/apiapp.go index e1862be..4eab288 100644 --- a/cmd/commands/api/apiapp.go +++ b/cmd/commands/api/apiapp.go @@ -35,7 +35,7 @@ var CmdApiapp = &commands.Command{ The command 'api' creates a Beego API application. {{"Example:"|bold}} - $ bee api [appname] [-tables=""] [-driver=mysql] [-conn=root:@tcp(127.0.0.1:3306)/test] + $ bee api [appname] [-tables=""] [-driver=mysql] [-conn="root:@tcp(127.0.0.1:3306)/test"] If 'conn' argument is empty, the command will generate an example API application. Otherwise the command will connect to your database and generate models based on the existing tables. From babd8d04b4287dce7dea98b373a01008ee7c8f45 Mon Sep 17 00:00:00 2001 From: "Hank.Lu" Date: Thu, 6 Dec 2018 15:01:38 +0800 Subject: [PATCH 02/11] Update hprose.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit db连接信息使用双引号包含 --- cmd/commands/hprose/hprose.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/commands/hprose/hprose.go b/cmd/commands/hprose/hprose.go index 135070f..1d50581 100644 --- a/cmd/commands/hprose/hprose.go +++ b/cmd/commands/hprose/hprose.go @@ -24,7 +24,7 @@ var CmdHproseapp = &commands.Command{ {{"To scaffold out your application, use:"|bold}} - $ bee hprose [appname] [-tables=""] [-driver=mysql] [-conn=root:@tcp(127.0.0.1:3306)/test] + $ bee hprose [appname] [-tables=""] [-driver=mysql] [-conn="root:@tcp(127.0.0.1:3306)/test"] If 'conn' is empty, the command will generate a sample application. Otherwise the command will connect to your database and generate models based on the existing tables. From 8252ea9f88f37eb7f00a9fb925b0de7f7c4dd026 Mon Sep 17 00:00:00 2001 From: sanghee Date: Fri, 4 Jan 2019 23:04:38 +0900 Subject: [PATCH 03/11] When restarting, terminate process gracefully --- cmd/commands/run/watch.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/cmd/commands/run/watch.go b/cmd/commands/run/watch.go index be547cb..5e9783a 100644 --- a/cmd/commands/run/watch.go +++ b/cmd/commands/run/watch.go @@ -148,7 +148,7 @@ func AutoBuild(files []string, isgenerate bool) { } appName := appname if err == nil { - + if runtime.GOOS == "windows" { appName += ".exe" } @@ -183,9 +183,20 @@ func Kill() { } }() if cmd != nil && cmd.Process != nil { - err := cmd.Process.Kill() - if err != nil { - beeLogger.Log.Errorf("Error while killing cmd process: %s", err) + //err := cmd.Process.Kill() + cmd.Process.Signal(os.Interrupt) + ch := make(chan struct{}, 1) + go func() { + cmd.Wait() + ch <- struct{}{} + }() + select { + case <-ch: + return + case <-time.After(10 * time.Second): + beeLogger.Log.Info("Timeout; Force kill cmd process") + cmd.Process.Kill() + return } } } From 87a287cac22969c6f6dc5519438961b8842d4fd5 Mon Sep 17 00:00:00 2001 From: sanghee Date: Fri, 4 Jan 2019 23:28:36 +0900 Subject: [PATCH 04/11] Remove comments and add error handling --- cmd/commands/run/watch.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/commands/run/watch.go b/cmd/commands/run/watch.go index 5e9783a..e852233 100644 --- a/cmd/commands/run/watch.go +++ b/cmd/commands/run/watch.go @@ -183,7 +183,6 @@ func Kill() { } }() if cmd != nil && cmd.Process != nil { - //err := cmd.Process.Kill() cmd.Process.Signal(os.Interrupt) ch := make(chan struct{}, 1) go func() { @@ -195,7 +194,10 @@ func Kill() { return case <-time.After(10 * time.Second): beeLogger.Log.Info("Timeout; Force kill cmd process") - cmd.Process.Kill() + err := cmd.Process.Kill() + if err != nil { + beeLogger.Log.Errorf("Error while killing cmd process: %s", err) + } return } } From 19be52dc8cd771cfc50b64218204e4f0d9cc37ba Mon Sep 17 00:00:00 2001 From: Tavee Khunbida Date: Tue, 8 Jan 2019 00:34:51 +0700 Subject: [PATCH 05/11] Fix panic on running tests for newly generated project --- cmd/commands/api/apiapp.go | 2 +- cmd/commands/new/new.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/commands/api/apiapp.go b/cmd/commands/api/apiapp.go index e1862be..2803fd3 100644 --- a/cmd/commands/api/apiapp.go +++ b/cmd/commands/api/apiapp.go @@ -511,7 +511,7 @@ import ( ) func init() { - _, file, _, _ := runtime.Caller(1) + _, file, _, _ := runtime.Caller(0) apppath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".." + string(filepath.Separator)))) beego.TestBeegoInit(apppath) } diff --git a/cmd/commands/new/new.go b/cmd/commands/new/new.go index 299f094..120efa2 100644 --- a/cmd/commands/new/new.go +++ b/cmd/commands/new/new.go @@ -101,7 +101,7 @@ import ( ) func init() { - _, file, _, _ := runtime.Caller(1) + _, file, _, _ := runtime.Caller(0) apppath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".." + string(filepath.Separator)))) beego.TestBeegoInit(apppath) } From 79d6746aa22d4cffbe2d8895612d7cbd22858d27 Mon Sep 17 00:00:00 2001 From: Tavee Khunbida Date: Tue, 8 Jan 2019 01:02:14 +0700 Subject: [PATCH 06/11] Fix staticcheck failed - should use time.Until instead of t.Sub(time.Now()) (S1024) --- cmd/commands/dlv/dlv_amd64.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/commands/dlv/dlv_amd64.go b/cmd/commands/dlv/dlv_amd64.go index 6eda3fb..6ed5901 100644 --- a/cmd/commands/dlv/dlv_amd64.go +++ b/cmd/commands/dlv/dlv_amd64.go @@ -227,7 +227,7 @@ func startWatcher(paths []string, ch chan int) { // Wait 1s before re-build until there is no file change scheduleTime := time.Now().Add(1 * time.Second) - time.Sleep(scheduleTime.Sub(time.Now())) + time.Until(scheduleTime) _, err := buildDebug() if err != nil { utils.Notify("Build Failed: "+err.Error(), "bee") From d24c05d83ef389db389342672475255eb3c6b082 Mon Sep 17 00:00:00 2001 From: Tavee Khunbida Date: Tue, 8 Jan 2019 01:03:58 +0700 Subject: [PATCH 07/11] Fix staticcheck failed - should use time.Until instead of t.Sub(time.Now()) (S1024) --- cmd/commands/run/watch.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/commands/run/watch.go b/cmd/commands/run/watch.go index be547cb..6ad984b 100644 --- a/cmd/commands/run/watch.go +++ b/cmd/commands/run/watch.go @@ -85,7 +85,7 @@ func NewWatcher(paths []string, files []string, isgenerate bool) { go func() { // Wait 1s before autobuild until there is no file change. scheduleTime = time.Now().Add(1 * time.Second) - time.Sleep(scheduleTime.Sub(time.Now())) + time.Until(scheduleTime) AutoBuild(files, isgenerate) if config.Conf.EnableReload { @@ -148,7 +148,7 @@ func AutoBuild(files []string, isgenerate bool) { } appName := appname if err == nil { - + if runtime.GOOS == "windows" { appName += ".exe" } From f2696160ae921f28e7baae12585d2e51ad537344 Mon Sep 17 00:00:00 2001 From: Tavee Khunbida Date: Tue, 8 Jan 2019 01:04:40 +0700 Subject: [PATCH 08/11] Fix staticcheck failed - error strings should not be capitalized (ST1005) --- generate/swaggergen/g_docs.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/generate/swaggergen/g_docs.go b/generate/swaggergen/g_docs.go index 71c13bd..77ece10 100644 --- a/generate/swaggergen/g_docs.go +++ b/generate/swaggergen/g_docs.go @@ -32,7 +32,7 @@ import ( "strings" "unicode" - "gopkg.in/yaml.v2" + yaml "gopkg.in/yaml.v2" "github.com/astaxie/beego/swagger" "github.com/astaxie/beego/utils" @@ -124,7 +124,7 @@ func ParsePackagesFromDir(dirpath string) { err = parsePackageFromDir(fpath) if err != nil { // Send the error to through the channel and continue walking - c <- fmt.Errorf("Error while parsing directory: %s", err.Error()) + c <- fmt.Errorf("error while parsing directory: %s", err.Error()) return nil } } From 22af6cc712324ad9cbb9ce323989a2b81b17a4a4 Mon Sep 17 00:00:00 2001 From: Tavee Khunbida Date: Tue, 8 Jan 2019 01:07:11 +0700 Subject: [PATCH 09/11] Fix staticcheck failed - cutset contains duplicate characters (SA1024) --- generate/swaggergen/g_docs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generate/swaggergen/g_docs.go b/generate/swaggergen/g_docs.go index 77ece10..e24656d 100644 --- a/generate/swaggergen/g_docs.go +++ b/generate/swaggergen/g_docs.go @@ -541,7 +541,7 @@ func parserComments(f *ast.FuncDecl, controllerName, pkgpath string) error { //TODO: resultMap := buildParamMap(f.Type.Results) if comments != nil && comments.List != nil { for _, c := range comments.List { - t := strings.TrimSpace(strings.TrimLeft(c.Text, "//")) + t := strings.TrimSpace(strings.TrimPrefix(c.Text, "//")) if strings.HasPrefix(t, "@router") { elements := strings.TrimSpace(t[len("@router"):]) e1 := strings.SplitN(elements, " ", 2) From 4d1304b78c3f61cf19bf202d29197c195913d160 Mon Sep 17 00:00:00 2001 From: Tavee Khunbida Date: Tue, 8 Jan 2019 01:08:03 +0700 Subject: [PATCH 10/11] Fix staticcheck failed - error strings should not be capitalized (ST1005) --- utils/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/utils.go b/utils/utils.go index 13e50b1..75b6898 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -328,7 +328,7 @@ func CheckEnv(appname string) (apppath, packpath string, err error) { apppath = filepath.Join(gosrcpath, appname) if _, e := os.Stat(apppath); !os.IsNotExist(e) { - err = fmt.Errorf("Cannot create application without removing '%s' first", apppath) + err = fmt.Errorf("cannot create application without removing '%s' first", apppath) beeLogger.Log.Errorf("Path '%s' already exists", apppath) return } From df31f04b2689a9d048e948f7c26860ef89fcd771 Mon Sep 17 00:00:00 2001 From: Tavee Khunbida Date: Tue, 8 Jan 2019 22:21:19 +0700 Subject: [PATCH 11/11] Fix accidently removed time.Sleep --- cmd/commands/dlv/dlv_amd64.go | 2 +- cmd/commands/run/watch.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/commands/dlv/dlv_amd64.go b/cmd/commands/dlv/dlv_amd64.go index 6ed5901..a61a5fa 100644 --- a/cmd/commands/dlv/dlv_amd64.go +++ b/cmd/commands/dlv/dlv_amd64.go @@ -227,7 +227,7 @@ func startWatcher(paths []string, ch chan int) { // Wait 1s before re-build until there is no file change scheduleTime := time.Now().Add(1 * time.Second) - time.Until(scheduleTime) + time.Sleep(time.Until(scheduleTime)) _, err := buildDebug() if err != nil { utils.Notify("Build Failed: "+err.Error(), "bee") diff --git a/cmd/commands/run/watch.go b/cmd/commands/run/watch.go index 6ad984b..f698f71 100644 --- a/cmd/commands/run/watch.go +++ b/cmd/commands/run/watch.go @@ -85,7 +85,7 @@ func NewWatcher(paths []string, files []string, isgenerate bool) { go func() { // Wait 1s before autobuild until there is no file change. scheduleTime = time.Now().Add(1 * time.Second) - time.Until(scheduleTime) + time.Sleep(time.Until(scheduleTime)) AutoBuild(files, isgenerate) if config.Conf.EnableReload {