From 285e130505144498fbbd5ff99210b2bb22e67e00 Mon Sep 17 00:00:00 2001 From: fanngyuan Date: Tue, 27 Aug 2013 22:35:48 +0800 Subject: [PATCH 1/9] add template --- apiapp.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/apiapp.go b/apiapp.go index 18b1a91..175e59f 100644 --- a/apiapp.go +++ b/apiapp.go @@ -54,6 +54,7 @@ import ( func main() { beego.RESTRouter("/object", &controllers.ObejctController{}) + beego.Router("/ping", &controllers.ObejctController{},"get:Ping") beego.Run() } ` @@ -170,8 +171,33 @@ func (this *ObejctController) Delete() { this.Data["json"] = "delete success!" this.ServeJson() } + +func (this *ObejctController) Ping() { + this.Ctx.WriteString("pong") +} + ` +var apiTests = `package tests + +import ( + "testing" + beetest "github.com/fanngyuan/beego/testing" + "io/ioutil" +) + +func TestHelloWorld(t *testing.T) { + request:=beetest.Get("/ping") + response,_:=request.Response() + defer response.Body.Close() + contents, _ := ioutil.ReadAll(response.Body) + if string(contents)!="pong"{ + t.Errorf("response sould be pong") + } +} + +` + func init() { cmdApiapp.Run = createapi } @@ -205,6 +231,10 @@ func createapi(cmd *Command, args []string) { writetofile(path.Join(apppath, "controllers", "default.go"), strings.Replace(apiControllers, "{{.Appname}}", packpath, -1)) + fmt.Println("create tests default.go:", path.Join(apppath, "tests", "default_test.go")) + writetofile(path.Join(apppath, "tests", "default_test.go"), + apiTests) + fmt.Println("create models object.go:", path.Join(apppath, "models", "object.go")) writetofile(path.Join(apppath, "models", "object.go"), apiModels) From f839552b8dbfe035907021b2dbfeba6987d00828 Mon Sep 17 00:00:00 2001 From: fanngyuan Date: Wed, 28 Aug 2013 11:04:12 +0800 Subject: [PATCH 2/9] fix bug --- apiapp.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apiapp.go b/apiapp.go index 175e59f..7ee4417 100644 --- a/apiapp.go +++ b/apiapp.go @@ -182,7 +182,7 @@ var apiTests = `package tests import ( "testing" - beetest "github.com/fanngyuan/beego/testing" + beetest "github.com/astaxie/beego/testing" "io/ioutil" ) From 550cf6cb716b6d71de45ddc9f22654d7366ebd9c Mon Sep 17 00:00:00 2001 From: astaxie Date: Wed, 11 Sep 2013 18:18:02 +0800 Subject: [PATCH 3/9] update apiapp --- apiapp.go | 514 +++++++++++++++++++++++++++--------------------------- 1 file changed, 257 insertions(+), 257 deletions(-) diff --git a/apiapp.go b/apiapp.go index 7ee4417..ef16306 100644 --- a/apiapp.go +++ b/apiapp.go @@ -1,183 +1,183 @@ -package main - -import ( - "fmt" - "os" - path "path/filepath" - "strings" -) - -var cmdApiapp = &Command{ - // CustomFlags: true, - UsageLine: "api [appname]", - Short: "create an api application base on beego framework", - Long: ` -create an api application base on beego framework - -In the current path, will create a folder named [appname] - -In the appname folder has the follow struct: - - ├── conf - │ └── app.conf - ├── controllers - │ └── default.go - ├── main.go - └── models - └── object.go - -`, -} - -var apiconf = ` -appname = {{.Appname}} -httpport = 8080 -runmode = dev -autorender = false -copyrequestbody = true -` -var apiMaingo = `package main - -import ( - "github.com/astaxie/beego" - "{{.Appname}}/controllers" -) - -// Objects - -// URL HTTP Verb Functionality -// /object POST Creating Objects -// /object/ GET Retrieving Objects -// /object/ PUT Updating Objects -// /object GET Queries -// /object/ DELETE Deleting Objects - -func main() { - beego.RESTRouter("/object", &controllers.ObejctController{}) +package main + +import ( + "fmt" + "os" + path "path/filepath" + "strings" +) + +var cmdApiapp = &Command{ + // CustomFlags: true, + UsageLine: "api [appname]", + Short: "create an api application base on beego framework", + Long: ` +create an api application base on beego framework + +In the current path, will create a folder named [appname] + +In the appname folder has the follow struct: + + ├── conf + │ └── app.conf + ├── controllers + │ └── default.go + ├── main.go + └── models + └── object.go + +`, +} + +var apiconf = ` +appname = {{.Appname}} +httpport = 8080 +runmode = dev +autorender = false +copyrequestbody = true +` +var apiMaingo = `package main + +import ( + "github.com/astaxie/beego" + "{{.Appname}}/controllers" +) + +// Objects + +// URL HTTP Verb Functionality +// /object POST Creating Objects +// /object/ GET Retrieving Objects +// /object/ PUT Updating Objects +// /object GET Queries +// /object/ DELETE Deleting Objects + +func main() { + beego.RESTRouter("/object", &controllers.ObejctController{}) beego.Router("/ping", &controllers.ObejctController{},"get:Ping") - beego.Run() -} -` -var apiModels = `package models - -import ( - "errors" - "strconv" - "time" -) - -var ( - Objects map[string]*Object -) - -type Object struct { - ObjectId string - Score int64 - PlayerName string -} - -func init() { - Objects = make(map[string]*Object) - Objects["hjkhsbnmn123"] = &Object{"hjkhsbnmn123", 100, "astaxie"} - Objects["mjjkxsxsaa23"] = &Object{"mjjkxsxsaa23", 101, "someone"} -} - -func AddOne(object Object) (ObjectId string) { - object.ObjectId = "astaxie" + strconv.FormatInt(time.Now().UnixNano(), 10) - Objects[object.ObjectId] = &object - return object.ObjectId -} - -func GetOne(ObjectId string) (object *Object, err error) { - if v, ok := Objects[ObjectId]; ok { - return v, nil - } - return nil, errors.New("ObjectId Not Exist") -} - -func GetAll() map[string]*Object { - return Objects -} - -func Update(ObjectId string, Score int64) (err error) { - if v, ok := Objects[ObjectId]; ok { - v.Score = Score - return nil - } - return errors.New("ObjectId Not Exist") -} - -func Delete(ObjectId string) { - delete(Objects, ObjectId) -} -` - -var apiControllers = `package controllers - -import ( - "encoding/json" - "github.com/astaxie/beego" - "{{.Appname}}/models" -) - -type ResponseInfo struct { -} - -type ObejctController struct { - beego.Controller -} - -func (this *ObejctController) Post() { - var ob models.Object - json.Unmarshal(this.Ctx.RequestBody, &ob) - objectid := models.AddOne(ob) - this.Data["json"] = map[string]string{"ObjectId": objectid} - this.ServeJson() -} - -func (this *ObejctController) Get() { - objectId := this.Ctx.Params[":objectId"] - if objectId != "" { - ob, err := models.GetOne(objectId) - if err != nil { - this.Data["json"] = err - } else { - this.Data["json"] = ob - } - } else { - obs := models.GetAll() - this.Data["json"] = obs - } - this.ServeJson() -} - -func (this *ObejctController) Put() { - objectId := this.Ctx.Params[":objectId"] - var ob models.Object - json.Unmarshal(this.Ctx.RequestBody, &ob) - - err := models.Update(objectId, ob.Score) - if err != nil { - this.Data["json"] = err - } else { - this.Data["json"] = "update success!" - } - this.ServeJson() -} - -func (this *ObejctController) Delete() { - objectId := this.Ctx.Params[":objectId"] - models.Delete(objectId) - this.Data["json"] = "delete success!" - this.ServeJson() -} + beego.Run() +} +` +var apiModels = `package models -func (this *ObejctController) Ping() { +import ( + "errors" + "strconv" + "time" +) + +var ( + Objects map[string]*Object +) + +type Object struct { + ObjectId string + Score int64 + PlayerName string +} + +func init() { + Objects = make(map[string]*Object) + Objects["hjkhsbnmn123"] = &Object{"hjkhsbnmn123", 100, "astaxie"} + Objects["mjjkxsxsaa23"] = &Object{"mjjkxsxsaa23", 101, "someone"} +} + +func AddOne(object Object) (ObjectId string) { + object.ObjectId = "astaxie" + strconv.FormatInt(time.Now().UnixNano(), 10) + Objects[object.ObjectId] = &object + return object.ObjectId +} + +func GetOne(ObjectId string) (object *Object, err error) { + if v, ok := Objects[ObjectId]; ok { + return v, nil + } + return nil, errors.New("ObjectId Not Exist") +} + +func GetAll() map[string]*Object { + return Objects +} + +func Update(ObjectId string, Score int64) (err error) { + if v, ok := Objects[ObjectId]; ok { + v.Score = Score + return nil + } + return errors.New("ObjectId Not Exist") +} + +func Delete(ObjectId string) { + delete(Objects, ObjectId) +} +` + +var apiControllers = `package controllers + +import ( + "encoding/json" + "github.com/astaxie/beego" + "{{.Appname}}/models" +) + +type ResponseInfo struct { +} + +type ObejctController struct { + beego.Controller +} + +func (this *ObejctController) Post() { + var ob models.Object + json.Unmarshal(this.Ctx.Input.RequestBody, &ob) + objectid := models.AddOne(ob) + this.Data["json"] = map[string]string{"ObjectId": objectid} + this.ServeJson() +} + +func (this *ObejctController) Get() { + objectId := this.Ctx.Params[":objectId"] + if objectId != "" { + ob, err := models.GetOne(objectId) + if err != nil { + this.Data["json"] = err + } else { + this.Data["json"] = ob + } + } else { + obs := models.GetAll() + this.Data["json"] = obs + } + this.ServeJson() +} + +func (this *ObejctController) Put() { + objectId := this.Ctx.Params[":objectId"] + var ob models.Object + json.Unmarshal(this.Ctx.Input.RequestBody, &ob) + + err := models.Update(objectId, ob.Score) + if err != nil { + this.Data["json"] = err + } else { + this.Data["json"] = "update success!" + } + this.ServeJson() +} + +func (this *ObejctController) Delete() { + objectId := this.Ctx.Input.Params[":objectId"] + models.Delete(objectId) + this.Data["json"] = "delete success!" + this.ServeJson() +} + +func (this *ObejctController) Ping() { this.Ctx.WriteString("pong") -} +} + +` -` - var apiTests = `package tests import ( @@ -198,88 +198,88 @@ func TestHelloWorld(t *testing.T) { ` -func init() { - cmdApiapp.Run = createapi -} - -func createapi(cmd *Command, args []string) { - if len(args) != 1 { - fmt.Println("error args") - os.Exit(2) - } - apppath, packpath, err := checkEnv(args[0]) - if err != nil { - fmt.Println(err) - os.Exit(2) - } - os.MkdirAll(apppath, 0755) - fmt.Println("create app folder:", apppath) - os.Mkdir(path.Join(apppath, "conf"), 0755) - fmt.Println("create conf:", path.Join(apppath, "conf")) - os.Mkdir(path.Join(apppath, "controllers"), 0755) - fmt.Println("create controllers:", path.Join(apppath, "controllers")) - os.Mkdir(path.Join(apppath, "models"), 0755) - fmt.Println("create models:", path.Join(apppath, "models")) - os.Mkdir(path.Join(apppath, "tests"), 0755) - fmt.Println("create tests:", path.Join(apppath, "tests")) - - fmt.Println("create conf app.conf:", path.Join(apppath, "conf", "app.conf")) - writetofile(path.Join(apppath, "conf", "app.conf"), - strings.Replace(apiconf, "{{.Appname}}", args[0], -1)) - - fmt.Println("create controllers default.go:", path.Join(apppath, "controllers", "default.go")) - writetofile(path.Join(apppath, "controllers", "default.go"), - strings.Replace(apiControllers, "{{.Appname}}", packpath, -1)) - +func init() { + cmdApiapp.Run = createapi +} + +func createapi(cmd *Command, args []string) { + if len(args) != 1 { + fmt.Println("error args") + os.Exit(2) + } + apppath, packpath, err := checkEnv(args[0]) + if err != nil { + fmt.Println(err) + os.Exit(2) + } + os.MkdirAll(apppath, 0755) + fmt.Println("create app folder:", apppath) + os.Mkdir(path.Join(apppath, "conf"), 0755) + fmt.Println("create conf:", path.Join(apppath, "conf")) + os.Mkdir(path.Join(apppath, "controllers"), 0755) + fmt.Println("create controllers:", path.Join(apppath, "controllers")) + os.Mkdir(path.Join(apppath, "models"), 0755) + fmt.Println("create models:", path.Join(apppath, "models")) + os.Mkdir(path.Join(apppath, "tests"), 0755) + fmt.Println("create tests:", path.Join(apppath, "tests")) + + fmt.Println("create conf app.conf:", path.Join(apppath, "conf", "app.conf")) + writetofile(path.Join(apppath, "conf", "app.conf"), + strings.Replace(apiconf, "{{.Appname}}", args[0], -1)) + + fmt.Println("create controllers default.go:", path.Join(apppath, "controllers", "default.go")) + writetofile(path.Join(apppath, "controllers", "default.go"), + strings.Replace(apiControllers, "{{.Appname}}", packpath, -1)) + fmt.Println("create tests default.go:", path.Join(apppath, "tests", "default_test.go")) writetofile(path.Join(apppath, "tests", "default_test.go"), apiTests) - fmt.Println("create models object.go:", path.Join(apppath, "models", "object.go")) - writetofile(path.Join(apppath, "models", "object.go"), apiModels) - - fmt.Println("create main.go:", path.Join(apppath, "main.go")) - writetofile(path.Join(apppath, "main.go"), - strings.Replace(apiMaingo, "{{.Appname}}", packpath, -1)) -} - -func checkEnv(appname string) (apppath, packpath string, err error) { - curpath, err := os.Getwd() - if err != nil { - return - } - - gopath := os.Getenv("GOPATH") - Debugf("gopath:%s", gopath) - if gopath == "" { - err = fmt.Errorf("you should set GOPATH in the env") - return - } - - appsrcpath := "" - haspath := false - wgopath := path.SplitList(gopath) - for _, wg := range wgopath { - wg = path.Join(wg, "src") - - if path.HasPrefix(strings.ToLower(curpath), strings.ToLower(wg)) { - haspath = true - appsrcpath = wg - break - } - } - - if !haspath { - err = fmt.Errorf("can't create application outside of GOPATH `%s`\n"+ - "you first should `cd $GOPATH%ssrc` then use create\n", gopath, string(path.Separator)) - return - } - apppath = path.Join(curpath, appname) - - if _, e := os.Stat(apppath); os.IsNotExist(e) == false { - err = fmt.Errorf("path `%s` exists, can not create app without remove it\n", apppath) - return - } - packpath = strings.Join(strings.Split(apppath[len(appsrcpath)+1:], string(path.Separator)), "/") - return -} + fmt.Println("create models object.go:", path.Join(apppath, "models", "object.go")) + writetofile(path.Join(apppath, "models", "object.go"), apiModels) + + fmt.Println("create main.go:", path.Join(apppath, "main.go")) + writetofile(path.Join(apppath, "main.go"), + strings.Replace(apiMaingo, "{{.Appname}}", packpath, -1)) +} + +func checkEnv(appname string) (apppath, packpath string, err error) { + curpath, err := os.Getwd() + if err != nil { + return + } + + gopath := os.Getenv("GOPATH") + Debugf("gopath:%s", gopath) + if gopath == "" { + err = fmt.Errorf("you should set GOPATH in the env") + return + } + + appsrcpath := "" + haspath := false + wgopath := path.SplitList(gopath) + for _, wg := range wgopath { + wg = path.Join(wg, "src") + + if path.HasPrefix(strings.ToLower(curpath), strings.ToLower(wg)) { + haspath = true + appsrcpath = wg + break + } + } + + if !haspath { + err = fmt.Errorf("can't create application outside of GOPATH `%s`\n"+ + "you first should `cd $GOPATH%ssrc` then use create\n", gopath, string(path.Separator)) + return + } + apppath = path.Join(curpath, appname) + + if _, e := os.Stat(apppath); os.IsNotExist(e) == false { + err = fmt.Errorf("path `%s` exists, can not create app without remove it\n", apppath) + return + } + packpath = strings.Join(strings.Split(apppath[len(appsrcpath)+1:], string(path.Separator)), "/") + return +} From 69761e3715358ce92f33195670a884c205aa8779 Mon Sep 17 00:00:00 2001 From: ssx205 Date: Thu, 12 Sep 2013 19:20:48 +0800 Subject: [PATCH 4/9] fmt code, and fix bug(bee new has wrong path seprator in windows) --- new.go | 2 +- test.go | 22 +++++++++++----------- watch.go | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/new.go b/new.go index b4ed4ca..4e95925 100644 --- a/new.go +++ b/new.go @@ -108,7 +108,7 @@ func createApp(cmd *Command, args []string) { writetofile(path.Join(apppath, "views", "index.tpl"), indextpl) fmt.Println(path.Join(apppath, "main.go")) - writetofile(path.Join(apppath, "main.go"), strings.Replace(maingo, "{{.Appname}}", strings.Join(strings.Split(apppath[len(appsrcpath)+1:], string(path.Separator)), string(path.Separator)), -1)) + writetofile(path.Join(apppath, "main.go"), strings.Replace(maingo, "{{.Appname}}", strings.Join(strings.Split(apppath[len(appsrcpath)+1:], string(path.Separator)), "/"), -1)) colorLog("[SUCC] New application successfully created!\n") } diff --git a/test.go b/test.go index 56446b4..efa8aee 100644 --- a/test.go +++ b/test.go @@ -1,24 +1,24 @@ package main import ( - "os" - path "path/filepath" - "os/exec" - "time" "bytes" + "os" + "os/exec" + path "path/filepath" + "time" ) var cmdTest = &Command{ UsageLine: "test [appname]", Short: "test the app", - Long: ``, + Long: ``, } func init() { cmdTest.Run = testApp } -var started= make(chan bool) +var started = make(chan bool) func testApp(cmd *Command, args []string) { if len(args) != 1 { @@ -56,15 +56,15 @@ func testApp(cmd *Command, args []string) { } } -func runTest(){ +func runTest() { colorLog("[INFO] Start testing...\n") - time.Sleep(time.Second*5) + time.Sleep(time.Second * 5) path, _ := os.Getwd() - os.Chdir(path+"/tests") + os.Chdir(path + "/tests") var err error icmd := exec.Command("go", "test") - var out,errbuffer bytes.Buffer + var out, errbuffer bytes.Buffer icmd.Stdout = &out icmd.Stderr = &errbuffer colorLog("[INFO] ============== Test Begin ===================\n") @@ -75,7 +75,7 @@ func runTest(){ if err != nil { colorLog("[ERRO] ============== Test failed ===================\n") - colorLog("[ERRO] " ,err) + colorLog("[ERRO] ", err) return } colorLog("[SUCC] Test finish\n") diff --git a/watch.go b/watch.go index 34cd6a7..5c3e9c7 100644 --- a/watch.go +++ b/watch.go @@ -147,7 +147,7 @@ func Start(appname string) { cmd.Stderr = os.Stderr go cmd.Run() - started<-true + started <- true } // checkTMPFile returns true if the event was for TMP files. From e8df0b125f93cf4e0986d34388880262909e51cb Mon Sep 17 00:00:00 2001 From: Xuyuan Pang Date: Fri, 13 Sep 2013 15:32:58 +0800 Subject: [PATCH 5/9] some misstakes on creating api app --- apiapp.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/apiapp.go b/apiapp.go index ef16306..b156869 100644 --- a/apiapp.go +++ b/apiapp.go @@ -53,8 +53,8 @@ import ( // /object/ DELETE Deleting Objects func main() { - beego.RESTRouter("/object", &controllers.ObejctController{}) - beego.Router("/ping", &controllers.ObejctController{},"get:Ping") + beego.RESTRouter("/object", &controllers.ObjectController{}) + beego.Router("/ping", &controllers.ObjectController{},"get:Ping") beego.Run() } ` @@ -123,11 +123,11 @@ import ( type ResponseInfo struct { } -type ObejctController struct { +type ObjectController struct { beego.Controller } -func (this *ObejctController) Post() { +func (this *ObjectController) Post() { var ob models.Object json.Unmarshal(this.Ctx.Input.RequestBody, &ob) objectid := models.AddOne(ob) @@ -135,8 +135,8 @@ func (this *ObejctController) Post() { this.ServeJson() } -func (this *ObejctController) Get() { - objectId := this.Ctx.Params[":objectId"] +func (this *ObjectController) Get() { + objectId := this.Ctx.Input.Param[":objectId"] if objectId != "" { ob, err := models.GetOne(objectId) if err != nil { @@ -151,8 +151,8 @@ func (this *ObejctController) Get() { this.ServeJson() } -func (this *ObejctController) Put() { - objectId := this.Ctx.Params[":objectId"] +func (this *ObjectController) Put() { + objectId := this.Ctx.Input.Param[":objectId"] var ob models.Object json.Unmarshal(this.Ctx.Input.RequestBody, &ob) @@ -165,14 +165,14 @@ func (this *ObejctController) Put() { this.ServeJson() } -func (this *ObejctController) Delete() { - objectId := this.Ctx.Input.Params[":objectId"] +func (this *ObjectController) Delete() { + objectId := this.Ctx.Input.Param[":objectId"] models.Delete(objectId) this.Data["json"] = "delete success!" this.ServeJson() } -func (this *ObejctController) Ping() { +func (this *ObjectController) Ping() { this.Ctx.WriteString("pong") } From 8115d5e1b82dc86a03ea7963ad74b4dd8a8a7601 Mon Sep 17 00:00:00 2001 From: shxsun Date: Tue, 24 Sep 2013 10:42:02 +0800 Subject: [PATCH 6/9] modify bee test for more competible with none beego project, and add func safePathAppend --- test.go | 58 +++++++++++++++++++++++++++++++++++++------------------- watch.go | 7 +++---- 2 files changed, 42 insertions(+), 23 deletions(-) diff --git a/test.go b/test.go index 56446b4..967c954 100644 --- a/test.go +++ b/test.go @@ -2,23 +2,38 @@ package main import ( "os" - path "path/filepath" "os/exec" + path "path/filepath" "time" - "bytes" + +// "bytes" ) var cmdTest = &Command{ UsageLine: "test [appname]", Short: "test the app", - Long: ``, + Long: ``, } func init() { cmdTest.Run = testApp } -var started= make(chan bool) +func safePathAppend(arr []string, paths ...string) []string { + for _, path := range paths { + if pathExists(path) { + arr = append(arr, path) + } + } + return arr +} + +func pathExists(path string) bool { + _, err := os.Stat(path) + return err == nil || os.IsExist(err) +} + +var started = make(chan bool) func testApp(cmd *Command, args []string) { if len(args) != 1 { @@ -34,7 +49,7 @@ func testApp(cmd *Command, args []string) { colorLog("[ERRO] Fail to parse bee.json[ %s ]", err) } var paths []string - paths = append(paths, + paths = safePathAppend(paths, path.Join(crupath, conf.DirStruct.Controllers), path.Join(crupath, conf.DirStruct.Models), path.Join(crupath, "./")) // Current path. @@ -50,32 +65,37 @@ func testApp(cmd *Command, args []string) { select { case <-started: runTest() - Kill() - os.Exit(0) + //Kill() + //os.Exit(0) } } } -func runTest(){ +func runTest() { colorLog("[INFO] Start testing...\n") - time.Sleep(time.Second*5) - path, _ := os.Getwd() - os.Chdir(path+"/tests") + time.Sleep(time.Second * 1) + crupwd, _ := os.Getwd() + testDir := path.Join(crupwd, "tests") + if pathExists(testDir) { + os.Chdir(testDir) + } var err error icmd := exec.Command("go", "test") - var out,errbuffer bytes.Buffer - icmd.Stdout = &out - icmd.Stderr = &errbuffer - colorLog("[INFO] ============== Test Begin ===================\n") + //var out,errbuffer bytes.Buffer + //icmd.Stdout = &out + //icmd.Stderr = &errbuffer + icmd.Stdout = os.Stdout + icmd.Stderr = os.Stderr + colorLog("[TRAC] ============== Test Begin ===================\n") err = icmd.Run() - colorLog(out.String()) - colorLog(errbuffer.String()) - colorLog("[INFO] ============== Test End ===================\n") + //colorLog(out.String()) + //colorLog(errbuffer.String()) + colorLog("[TRAC] ============== Test End ===================\n") if err != nil { colorLog("[ERRO] ============== Test failed ===================\n") - colorLog("[ERRO] " ,err) + colorLog("[ERRO] ", err) return } colorLog("[SUCC] Test finish\n") diff --git a/watch.go b/watch.go index 34cd6a7..b0c89c3 100644 --- a/watch.go +++ b/watch.go @@ -3,7 +3,6 @@ package main import ( "fmt" "github.com/howeyc/fsnotify" - "log" "os" "os/exec" "strings" @@ -51,7 +50,7 @@ func NewWatcher(paths []string) { go Autobuild() } case err := <-watcher.Error: - log.Fatal("error:", err) + colorLog("[WARN] %s\n", err.Error()) // No need to exit here } } }() @@ -125,7 +124,7 @@ func Kill() { fmt.Println("Kill -> ", e) } }() - if cmd != nil { + if cmd != nil && cmd.Process != nil { cmd.Process.Kill() } } @@ -147,7 +146,7 @@ func Start(appname string) { cmd.Stderr = os.Stderr go cmd.Run() - started<-true + started <- true } // checkTMPFile returns true if the event was for TMP files. From 33ff8482f76ee7a2b5151ed111bf91bb5009d983 Mon Sep 17 00:00:00 2001 From: Odiel Leon Date: Wed, 25 Sep 2013 23:22:35 -0400 Subject: [PATCH 7/9] - Moving + p { + margin: 0px 0px 10px; + } + +
From a10bc28ab4d3704869a8fcf12c2344373549f666 Mon Sep 17 00:00:00 2001 From: Odiel Leon Date: Thu, 26 Sep 2013 14:41:25 -0400 Subject: [PATCH 8/9] - Defining the logs levels as constants - Adding time for each log print in order to see changes in the console or logs files. --- util.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/util.go b/util.go index 6cafb46..a85063a 100644 --- a/util.go +++ b/util.go @@ -6,6 +6,7 @@ import ( "path/filepath" "runtime" "strings" + "time" ) // Go is a basic promise implementation: it wraps calls a function in a goroutine @@ -41,6 +42,11 @@ const ( Magenta //NRed = uint8(31) // Normal EndColor = "\033[0m" + + TRAC = "TRAC" + ERRO = "ERRO" + WARN = "WARN" + SUCC = "SUCC" ) // colorLog colors log and print to stdout. @@ -80,20 +86,22 @@ func colorLog(format string, a ...interface{}) { log = clog + log } - fmt.Print(log) + var currentTime = time.Now() + + fmt.Print(currentTime.Format("2006-01-02 03:04:05 "+log)) } // getColorLevel returns colored level string by given level. func getColorLevel(level string) string { level = strings.ToUpper(level) switch level { - case "TRAC": + case TRAC: return fmt.Sprintf("\033[%dm%s\033[0m", Blue, level) - case "ERRO": + case ERRO: return fmt.Sprintf("\033[%dm%s\033[0m", Red, level) - case "WARN": + case WARN: return fmt.Sprintf("\033[%dm%s\033[0m", Magenta, level) - case "SUCC": + case SUCC: return fmt.Sprintf("\033[%dm%s\033[0m", Green, level) default: return level From bd14fb59851086e13066f0ccad3161666f3fd235 Mon Sep 17 00:00:00 2001 From: Eryx Date: Fri, 4 Oct 2013 22:29:43 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E5=A4=9A=E4=BD=99=E7=9A=84=20html=20?= =?UTF-8?q?=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 多余的 html 标签 --- new.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/new.go b/new.go index eccc4bc..646fc3f 100644 --- a/new.go +++ b/new.go @@ -222,7 +222,7 @@ var indextpl = `
Official website: {{.Website}}
- Contact me: {{.Email}} + Contact me: {{.Email}}