1
0
mirror of https://github.com/beego/bee.git synced 2024-11-22 15:10:54 +00:00

Merge branch 'master' of github.com:beego/bee

This commit is contained in:
slene 2013-12-23 16:45:47 +08:00
commit d4cd5a0671
4 changed files with 46 additions and 27 deletions

View File

@ -150,7 +150,7 @@ func (this *ObjectController) Post() {
} }
func (this *ObjectController) Get() { func (this *ObjectController) Get() {
objectId := this.Ctx.Input.Param[":objectId"] objectId := this.Ctx.Input.Params[":objectId"]
if objectId != "" { if objectId != "" {
ob, err := models.GetOne(objectId) ob, err := models.GetOne(objectId)
if err != nil { if err != nil {
@ -166,7 +166,7 @@ func (this *ObjectController) Get() {
} }
func (this *ObjectController) Put() { func (this *ObjectController) Put() {
objectId := this.Ctx.Input.Param[":objectId"] objectId := this.Ctx.Input.Params[":objectId"]
var ob models.Object var ob models.Object
json.Unmarshal(this.Ctx.Input.RequestBody, &ob) json.Unmarshal(this.Ctx.Input.RequestBody, &ob)
@ -180,7 +180,7 @@ func (this *ObjectController) Put() {
} }
func (this *ObjectController) Delete() { func (this *ObjectController) Delete() {
objectId := this.Ctx.Input.Param[":objectId"] objectId := this.Ctx.Input.Params[":objectId"]
models.Delete(objectId) models.Delete(objectId)
this.Data["json"] = "delete success!" this.Data["json"] = "delete success!"
this.ServeJson() this.ServeJson()

View File

@ -41,6 +41,7 @@ var conf struct {
// gopm support // gopm support
Gopm struct { Gopm struct {
Enable bool Enable bool
Install bool
} }
// Indicates whether execute "go install" before "go build". // Indicates whether execute "go install" before "go build".
GoInstall bool `json:"go_install"` GoInstall bool `json:"go_install"`

View File

@ -46,7 +46,7 @@ compress an beego project
-ba additional args of go build -ba additional args of go build
-o compressed file output dir. default use current path -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 -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 -exs path exclude suffix. default: .go:.DS_Store:.tmp
all path use : as separator all path use : as separator
-fs follow symlink. default false -fs follow symlink. default false
@ -72,7 +72,7 @@ var (
func init() { func init() {
fs := flag.NewFlagSet("pack", flag.ContinueOnError) fs := flag.NewFlagSet("pack", flag.ContinueOnError)
fs.StringVar(&appPath, "p", "", "") fs.StringVar(&appPath, "p", "", "")
fs.StringVar(&excludeP, "exp", "", "") fs.StringVar(&excludeP, "exp", ".", "")
fs.StringVar(&excludeS, "exs", ".go:.DS_Store:.tmp", "") fs.StringVar(&excludeS, "exs", ".go:.DS_Store:.tmp", "")
fs.StringVar(&outputP, "o", "", "") fs.StringVar(&outputP, "o", "", "")
fs.BoolVar(&build, "b", true, "") fs.BoolVar(&build, "b", true, "")

View File

@ -15,6 +15,7 @@
package main package main
import ( import (
"bytes"
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
@ -30,6 +31,7 @@ var (
cmd *exec.Cmd cmd *exec.Cmd
state sync.Mutex state sync.Mutex
eventTime = make(map[string]int64) eventTime = make(map[string]int64)
buildPeriod time.Time
) )
func NewWatcher(paths []string) { func NewWatcher(paths []string) {
@ -53,6 +55,12 @@ func NewWatcher(paths []string) {
continue continue
} }
// Prevent duplicated builds.
if buildPeriod.Add(1 * time.Second).After(time.Now()) {
continue
}
buildPeriod = time.Now()
mt := getFileModTime(e.Name) mt := getFileModTime(e.Name)
if t := eventTime[e.Name]; mt == t { if t := eventTime[e.Name]; mt == t {
ColorLog("[SKIP] # %s #\n", e.String()) ColorLog("[SKIP] # %s #\n", e.String())
@ -69,8 +77,6 @@ func NewWatcher(paths []string) {
ColorLog("[WARN] %s\n", err.Error()) // No need to exit here ColorLog("[WARN] %s\n", err.Error()) // No need to exit here
} }
} }
time.Sleep(500 * time.Millisecond)
}() }()
ColorLog("[INFO] Initializing watcher...\n") ColorLog("[INFO] Initializing watcher...\n")
@ -120,11 +126,26 @@ func Autobuild() {
var err error var err error
// For applications use full import path like "github.com/.../.." // For applications use full import path like "github.com/.../.."
// are able to use "go install" to reduce build time. // 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 := 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
}
icmd = exec.Command(cmdName, "install", pkg)
icmd.Stdout = os.Stdout icmd.Stdout = os.Stdout
icmd.Stderr = os.Stderr icmd.Stderr = os.Stderr
err = icmd.Run() err = icmd.Run()
if err != nil {
break
}
}
}
} }
if err == nil { if err == nil {
@ -132,18 +153,12 @@ func Autobuild() {
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
appName += ".exe" appName += ".exe"
} }
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 := exec.Command(cmdName, "build")
bcmd.Stdout = os.Stdout bcmd.Stdout = os.Stdout
bcmd.Stderr = os.Stderr bcmd.Stderr = os.Stderr
err = bcmd.Run() err = bcmd.Run()
} }
}
if err != nil { if err != nil {
ColorLog("[ERRO] ============== Build failed ===================\n") ColorLog("[ERRO] ============== Build failed ===================\n")
@ -156,11 +171,14 @@ func Autobuild() {
func Kill() { func Kill() {
defer func() { defer func() {
if e := recover(); e != nil { if e := recover(); e != nil {
fmt.Println("Kill -> ", e) fmt.Println("Kill.recover -> ", e)
} }
}() }()
if cmd != nil && cmd.Process != nil { if cmd != nil && cmd.Process != nil {
cmd.Process.Kill() err := cmd.Process.Kill()
if err != nil {
fmt.Println("Kill -> ", err)
}
} }
} }