From 78a6597edb3e3e2bdbc25d793dfe4109ed728d7b Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 9 Dec 2013 11:11:26 -0500 Subject: [PATCH 1/9] Update --- watch.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/watch.go b/watch.go index 2f4ae67..d7500a7 100644 --- a/watch.go +++ b/watch.go @@ -27,9 +27,10 @@ import ( ) var ( - cmd *exec.Cmd - state sync.Mutex - eventTime = make(map[string]int64) + cmd *exec.Cmd + state sync.Mutex + eventTime = make(map[string]int64) + buildPeriod time.Time ) func NewWatcher(paths []string) { @@ -53,6 +54,12 @@ func NewWatcher(paths []string) { continue } + // Prevent duplicated builds. + if buildPeriod.Add(1 * time.Second).After(time.Now()) { + continue + } + buildPeriod = time.Now() + mt := getFileModTime(e.Name) if t := eventTime[e.Name]; mt == t { ColorLog("[SKIP] # %s #\n", e.String()) @@ -69,8 +76,6 @@ func NewWatcher(paths []string) { ColorLog("[WARN] %s\n", err.Error()) // No need to exit here } } - - time.Sleep(500 * time.Millisecond) }() ColorLog("[INFO] Initializing watcher...\n") From a7e6c6a9b5b8f9276471c1a4527d808819893607 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 9 Dec 2013 11:17:46 -0500 Subject: [PATCH 2/9] Update --- watch.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/watch.go b/watch.go index d7500a7..856f560 100644 --- a/watch.go +++ b/watch.go @@ -152,6 +152,9 @@ func Autobuild() { if err != nil { ColorLog("[ERRO] ============== Build failed ===================\n") + fmt.Print("Press 'enter' to rebuild...") + fmt.Scanln() + go Autobuild() return } ColorLog("[SUCC] Build was successful\n") From 3114e6153702dfdef8f0027dd76c055d9558f068 Mon Sep 17 00:00:00 2001 From: astaxie Date: Tue, 10 Dec 2013 10:00:17 +0800 Subject: [PATCH 3/9] fix param to params --- apiapp.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apiapp.go b/apiapp.go index f3038fa..87ade63 100644 --- a/apiapp.go +++ b/apiapp.go @@ -150,7 +150,7 @@ func (this *ObjectController) Post() { } func (this *ObjectController) Get() { - objectId := this.Ctx.Input.Param[":objectId"] + objectId := this.Ctx.Input.Params[":objectId"] if objectId != "" { ob, err := models.GetOne(objectId) if err != nil { @@ -166,7 +166,7 @@ func (this *ObjectController) Get() { } func (this *ObjectController) Put() { - objectId := this.Ctx.Input.Param[":objectId"] + objectId := this.Ctx.Input.Params[":objectId"] var ob models.Object json.Unmarshal(this.Ctx.Input.RequestBody, &ob) @@ -180,7 +180,7 @@ func (this *ObjectController) Put() { } func (this *ObjectController) Delete() { - objectId := this.Ctx.Input.Param[":objectId"] + objectId := this.Ctx.Input.Params[":objectId"] models.Delete(objectId) this.Data["json"] = "delete success!" this.ServeJson() From 49c53400ea336b3c5034eeed71c9c6bf3d778557 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 12 Dec 2013 17:13:50 -0500 Subject: [PATCH 4/9] Bug fixed --- conf.go | 3 ++- watch.go | 5 +---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/conf.go b/conf.go index 77e242f..e78dc41 100644 --- a/conf.go +++ b/conf.go @@ -40,7 +40,8 @@ var conf struct { Version int // gopm support Gopm struct { - Enable bool + Enable bool + Install bool } // Indicates whether execute "go install" before "go build". GoInstall bool `json:"go_install"` diff --git a/watch.go b/watch.go index 856f560..26b70a7 100644 --- a/watch.go +++ b/watch.go @@ -125,7 +125,7 @@ func Autobuild() { var err error // For applications use full import path like "github.com/.../.." // are able to use "go install" to reduce build time. - if conf.GoInstall { + if conf.GoInstall || conf.Gopm.Install { icmd := exec.Command(cmdName, "install") icmd.Stdout = os.Stdout icmd.Stderr = os.Stderr @@ -152,9 +152,6 @@ func Autobuild() { if err != nil { ColorLog("[ERRO] ============== Build failed ===================\n") - fmt.Print("Press 'enter' to rebuild...") - fmt.Scanln() - go Autobuild() return } ColorLog("[SUCC] Build was successful\n") From cce4f8c2898782dcb1e86e26278b865b57236765 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 13 Dec 2013 21:39:16 -0500 Subject: [PATCH 5/9] Bug fixed --- watch.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/watch.go b/watch.go index 26b70a7..b177907 100644 --- a/watch.go +++ b/watch.go @@ -137,6 +137,9 @@ func Autobuild() { if runtime.GOOS == "windows" { appName += ".exe" } + if isExist(appName) { + os.Remove(appName) + } binPath := GetGOPATHs()[0] + "/bin/" + appName if conf.GoInstall && isExist(binPath) { From c397d9720b303af3970847110f4bd3514f413d8c Mon Sep 17 00:00:00 2001 From: yaofangou Date: Sun, 15 Dec 2013 22:20:07 +0800 Subject: [PATCH 6/9] set exp default . --- pack.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pack.go b/pack.go index 305ef88..6c86853 100644 --- a/pack.go +++ b/pack.go @@ -45,7 +45,7 @@ compress an beego project -b build specify platform app. default true -o compressed file output dir. default use current path -f format. [ tar.gz / zip ]. default tar.gz. note: zip doesn't support embed symlink, skip it --exp path exclude prefix +-exp path exclude prefix. default: . -exs path exclude suffix. default: .go:.DS_Store:.tmp all path use : as separator -fs follow symlink. default false @@ -70,7 +70,7 @@ var ( func init() { fs := flag.NewFlagSet("pack", flag.ContinueOnError) fs.StringVar(&appPath, "p", "", "") - fs.StringVar(&excludeP, "exp", "", "") + fs.StringVar(&excludeP, "exp", ".", "") fs.StringVar(&excludeS, "exs", ".go:.DS_Store:.tmp", "") fs.StringVar(&outputP, "o", "", "") fs.BoolVar(&build, "b", true, "") From 342172a1acc99fac7f7721f4f7cd09edd2907fcc Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 15 Dec 2013 18:08:51 -0500 Subject: [PATCH 7/9] ug fixed --- watch.go | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/watch.go b/watch.go index b177907..d0572f1 100644 --- a/watch.go +++ b/watch.go @@ -15,6 +15,7 @@ package main import ( + "bytes" "fmt" "os" "os/exec" @@ -126,10 +127,24 @@ func Autobuild() { // For applications use full import path like "github.com/.../.." // are able to use "go install" to reduce build time. if conf.GoInstall || conf.Gopm.Install { - icmd := exec.Command(cmdName, "install") - icmd.Stdout = os.Stdout - icmd.Stderr = os.Stderr + icmd := exec.Command("go", "list", "./...") + buf := bytes.NewBuffer([]byte("")) + icmd.Stdout = buf err = icmd.Run() + if err == nil { + list := strings.Split(buf.String(), "\n")[1:] + for _, pkg := range list { + if len(pkg) == 0 { + continue + } + fmt.Println(pkg) + icmd = exec.Command(cmdName, "install", pkg) + err = icmd.Run() + if err != nil { + break + } + } + } } if err == nil { @@ -137,20 +152,11 @@ func Autobuild() { if runtime.GOOS == "windows" { appName += ".exe" } - if isExist(appName) { - os.Remove(appName) - } - binPath := GetGOPATHs()[0] + "/bin/" + appName - if conf.GoInstall && isExist(binPath) { - os.Rename(binPath, appName) - ColorLog("[INFO] Build command reduced\n") - } else { - bcmd := exec.Command(cmdName, "build") - bcmd.Stdout = os.Stdout - bcmd.Stderr = os.Stderr - err = bcmd.Run() - } + bcmd := exec.Command(cmdName, "build") + bcmd.Stdout = os.Stdout + bcmd.Stderr = os.Stderr + err = bcmd.Run() } if err != nil { @@ -164,11 +170,14 @@ func Autobuild() { func Kill() { defer func() { if e := recover(); e != nil { - fmt.Println("Kill -> ", e) + fmt.Println("Kill.recover -> ", e) } }() if cmd != nil && cmd.Process != nil { - cmd.Process.Kill() + err := cmd.Process.Kill() + if err != nil { + fmt.Println("Kill -> ", err) + } } } From 5b59147d87d75d525c3e4a8253e9feb6e2fb2346 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 15 Dec 2013 18:09:31 -0500 Subject: [PATCH 8/9] Bug fixed --- watch.go | 1 - 1 file changed, 1 deletion(-) diff --git a/watch.go b/watch.go index d0572f1..52c8c6a 100644 --- a/watch.go +++ b/watch.go @@ -137,7 +137,6 @@ func Autobuild() { if len(pkg) == 0 { continue } - fmt.Println(pkg) icmd = exec.Command(cmdName, "install", pkg) err = icmd.Run() if err != nil { From ebcc00b1132a4f63738659139a643bb99fd1e9d5 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 15 Dec 2013 18:28:17 -0500 Subject: [PATCH 9/9] Bug fixed --- watch.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/watch.go b/watch.go index 52c8c6a..e03ce48 100644 --- a/watch.go +++ b/watch.go @@ -138,6 +138,8 @@ func Autobuild() { continue } icmd = exec.Command(cmdName, "install", pkg) + icmd.Stdout = os.Stdout + icmd.Stderr = os.Stderr err = icmd.Run() if err != nil { break