mirror of
				https://github.com/beego/bee.git
				synced 2025-11-04 09:23:24 +00:00 
			
		
		
		
	Merge pull request #1 from beego/master
Merge branch 'master' of github.com:beego/bee
This commit is contained in:
		@@ -3,4 +3,8 @@ bee
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
[](https://drone.io/github.com/beego/bee/latest)
 | 
					[](https://drone.io/github.com/beego/bee/latest)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Bee is a tool for helping develop with beego app framework.
 | 
					Bee is a tool for helping develop with beego app framework.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Requirements
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- Go version >= 1.1.
 | 
				
			||||||
							
								
								
									
										72
									
								
								apiapp.go
									
									
									
									
									
								
							
							
						
						
									
										72
									
								
								apiapp.go
									
									
									
									
									
								
							@@ -36,9 +36,13 @@ In the appname folder has the follow struct:
 | 
				
			|||||||
	│   └── app.conf
 | 
						│   └── app.conf
 | 
				
			||||||
	├── controllers
 | 
						├── controllers
 | 
				
			||||||
	│   └── default.go
 | 
						│   └── default.go
 | 
				
			||||||
 | 
						├── routers
 | 
				
			||||||
 | 
						│   └── router.go
 | 
				
			||||||
 | 
						├── tests
 | 
				
			||||||
 | 
						│   └── default_test.go		
 | 
				
			||||||
	├── main.go
 | 
						├── main.go
 | 
				
			||||||
	└── models
 | 
						└── models
 | 
				
			||||||
	    └── object.go             
 | 
						    └── object.go            
 | 
				
			||||||
 | 
					
 | 
				
			||||||
`,
 | 
					`,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -53,8 +57,8 @@ copyrequestbody = true
 | 
				
			|||||||
var apiMaingo = `package main
 | 
					var apiMaingo = `package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"github.com/astaxie/beego"
 | 
						_ "{{.Appname}}/routers"
 | 
				
			||||||
	"{{.Appname}}/controllers"
 | 
						"github.com/astaxie/beego"	
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//		Objects
 | 
					//		Objects
 | 
				
			||||||
@@ -67,11 +71,21 @@ import (
 | 
				
			|||||||
//	/object/<objectId>	DELETE					Deleting Objects
 | 
					//	/object/<objectId>	DELETE					Deleting Objects
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func main() {
 | 
					func main() {
 | 
				
			||||||
	beego.RESTRouter("/object", &controllers.ObjectController{})
 | 
					 | 
				
			||||||
	beego.Router("/ping", &controllers.ObjectController{},"get:Ping")
 | 
					 | 
				
			||||||
	beego.Run()
 | 
						beego.Run()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
`
 | 
					`
 | 
				
			||||||
 | 
					var apirouter = `package routers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"{{.Appname}}/controllers"
 | 
				
			||||||
 | 
						"github.com/astaxie/beego"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func init() {
 | 
				
			||||||
 | 
					    beego.RESTRouter("/object", &controllers.ObjectController{})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var apiModels = `package models
 | 
					var apiModels = `package models
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
@@ -186,28 +200,36 @@ func (this *ObjectController) Delete() {
 | 
				
			|||||||
	this.ServeJson()
 | 
						this.ServeJson()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (this *ObjectController) Ping() {
 | 
					 | 
				
			||||||
    this.Ctx.WriteString("pong")
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
`
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var apiTests = `package tests
 | 
					var apiTests = `package test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
    "testing"
 | 
						"net/http"
 | 
				
			||||||
	beetest "github.com/astaxie/beego/testing"
 | 
						"net/http/httptest"
 | 
				
			||||||
	"io/ioutil"
 | 
						"testing"
 | 
				
			||||||
 | 
						_ "{{.Appname}}/routers"
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
						"github.com/astaxie/beego"
 | 
				
			||||||
 | 
						. "github.com/smartystreets/goconvey/convey"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestHelloWorld(t *testing.T) {
 | 
					// TestGet is a sample to run an endpoint test
 | 
				
			||||||
	request:=beetest.Get("/ping")
 | 
					func TestGet(t *testing.T) {
 | 
				
			||||||
	response,_:=request.Response()
 | 
						r, _ := http.NewRequest("GET", "/object", nil)
 | 
				
			||||||
	defer response.Body.Close()
 | 
						w := httptest.NewRecorder()
 | 
				
			||||||
	contents, _ := ioutil.ReadAll(response.Body)
 | 
						beego.BeeApp.Handlers.ServeHTTP(w, r)
 | 
				
			||||||
	if string(contents)!="pong"{
 | 
						
 | 
				
			||||||
        t.Errorf("response sould be pong")
 | 
						beego.Trace("testing", "TestGet", "Code[%d]\n%s", w.Code, w.Body.String())
 | 
				
			||||||
    }
 | 
						
 | 
				
			||||||
 | 
						Convey("Subject: Test Station Endpoint\n", t, func() {
 | 
				
			||||||
 | 
						        Convey("Status Code Should Be 200", func() {
 | 
				
			||||||
 | 
						                So(w.Code, ShouldEqual, 200)
 | 
				
			||||||
 | 
						        })
 | 
				
			||||||
 | 
						        Convey("The Result Should Not Be Empty", func() {
 | 
				
			||||||
 | 
						                So(w.Body.Len(), ShouldBeGreaterThan, 0)
 | 
				
			||||||
 | 
						        })
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
`
 | 
					`
 | 
				
			||||||
@@ -233,6 +255,8 @@ func createapi(cmd *Command, args []string) {
 | 
				
			|||||||
	os.Mkdir(path.Join(apppath, "controllers"), 0755)
 | 
						os.Mkdir(path.Join(apppath, "controllers"), 0755)
 | 
				
			||||||
	fmt.Println("create controllers:", path.Join(apppath, "controllers"))
 | 
						fmt.Println("create controllers:", path.Join(apppath, "controllers"))
 | 
				
			||||||
	os.Mkdir(path.Join(apppath, "models"), 0755)
 | 
						os.Mkdir(path.Join(apppath, "models"), 0755)
 | 
				
			||||||
 | 
						fmt.Println(path.Join(apppath, "routers") + string(path.Separator))
 | 
				
			||||||
 | 
						os.Mkdir(path.Join(apppath, "routers"), 0755)
 | 
				
			||||||
	fmt.Println("create models:", path.Join(apppath, "models"))
 | 
						fmt.Println("create models:", path.Join(apppath, "models"))
 | 
				
			||||||
	os.Mkdir(path.Join(apppath, "tests"), 0755)
 | 
						os.Mkdir(path.Join(apppath, "tests"), 0755)
 | 
				
			||||||
	fmt.Println("create tests:", path.Join(apppath, "tests"))
 | 
						fmt.Println("create tests:", path.Join(apppath, "tests"))
 | 
				
			||||||
@@ -247,7 +271,11 @@ func createapi(cmd *Command, args []string) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	fmt.Println("create tests default.go:", path.Join(apppath, "tests", "default_test.go"))
 | 
						fmt.Println("create tests default.go:", path.Join(apppath, "tests", "default_test.go"))
 | 
				
			||||||
	writetofile(path.Join(apppath, "tests", "default_test.go"),
 | 
						writetofile(path.Join(apppath, "tests", "default_test.go"),
 | 
				
			||||||
		apiTests)
 | 
							strings.Replace(apiTests, "{{.Appname}}", packpath, -1))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fmt.Println("create routers router.go:", path.Join(apppath, "routers", "router.go"))
 | 
				
			||||||
 | 
						writetofile(path.Join(apppath, "routers", "router.go"),
 | 
				
			||||||
 | 
							strings.Replace(apirouter, "{{.Appname}}", packpath, -1))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fmt.Println("create models object.go:", path.Join(apppath, "models", "object.go"))
 | 
						fmt.Println("create models object.go:", path.Join(apppath, "models", "object.go"))
 | 
				
			||||||
	writetofile(path.Join(apppath, "models", "object.go"), apiModels)
 | 
						writetofile(path.Join(apppath, "models", "object.go"), apiModels)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										63
									
								
								new.go
									
									
									
									
									
								
							
							
						
						
									
										63
									
								
								new.go
									
									
									
									
									
								
							@@ -37,7 +37,11 @@ The [appname] folder has following structure:
 | 
				
			|||||||
    |- controllers
 | 
					    |- controllers
 | 
				
			||||||
         |- default.go
 | 
					         |- default.go
 | 
				
			||||||
    |- models
 | 
					    |- models
 | 
				
			||||||
    |- static
 | 
					    |- routers
 | 
				
			||||||
 | 
					         |- router.go	
 | 
				
			||||||
 | 
					    |- tests
 | 
				
			||||||
 | 
					         |- default_test.go
 | 
				
			||||||
 | 
						|- static
 | 
				
			||||||
         |- js
 | 
					         |- js
 | 
				
			||||||
         |- css
 | 
					         |- css
 | 
				
			||||||
         |- img             
 | 
					         |- img             
 | 
				
			||||||
@@ -102,6 +106,10 @@ func createApp(cmd *Command, args []string) {
 | 
				
			|||||||
	fmt.Println(path.Join(apppath, "controllers") + string(path.Separator))
 | 
						fmt.Println(path.Join(apppath, "controllers") + string(path.Separator))
 | 
				
			||||||
	os.Mkdir(path.Join(apppath, "models"), 0755)
 | 
						os.Mkdir(path.Join(apppath, "models"), 0755)
 | 
				
			||||||
	fmt.Println(path.Join(apppath, "models") + string(path.Separator))
 | 
						fmt.Println(path.Join(apppath, "models") + string(path.Separator))
 | 
				
			||||||
 | 
						os.Mkdir(path.Join(apppath, "routers"), 0755)
 | 
				
			||||||
 | 
						fmt.Println(path.Join(apppath, "routers") + string(path.Separator))
 | 
				
			||||||
 | 
						os.Mkdir(path.Join(apppath, "tests"), 0755)
 | 
				
			||||||
 | 
						fmt.Println(path.Join(apppath, "tests") + string(path.Separator))
 | 
				
			||||||
	os.Mkdir(path.Join(apppath, "static"), 0755)
 | 
						os.Mkdir(path.Join(apppath, "static"), 0755)
 | 
				
			||||||
	fmt.Println(path.Join(apppath, "static") + string(path.Separator))
 | 
						fmt.Println(path.Join(apppath, "static") + string(path.Separator))
 | 
				
			||||||
	os.Mkdir(path.Join(apppath, "static", "js"), 0755)
 | 
						os.Mkdir(path.Join(apppath, "static", "js"), 0755)
 | 
				
			||||||
@@ -121,6 +129,12 @@ func createApp(cmd *Command, args []string) {
 | 
				
			|||||||
	fmt.Println(path.Join(apppath, "views", "index.tpl"))
 | 
						fmt.Println(path.Join(apppath, "views", "index.tpl"))
 | 
				
			||||||
	writetofile(path.Join(apppath, "views", "index.tpl"), indextpl)
 | 
						writetofile(path.Join(apppath, "views", "index.tpl"), indextpl)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fmt.Println(path.Join(apppath, "routers", "router.go"))
 | 
				
			||||||
 | 
						writetofile(path.Join(apppath, "routers", "router.go"), strings.Replace(router, "{{.Appname}}", strings.Join(strings.Split(apppath[len(appsrcpath)+1:], string(path.Separator)), "/"), -1))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fmt.Println(path.Join(apppath, "tests", "default_test.go"))
 | 
				
			||||||
 | 
						writetofile(path.Join(apppath, "tests", "default_test.go"), strings.Replace(test, "{{.Appname}}", strings.Join(strings.Split(apppath[len(appsrcpath)+1:], string(path.Separator)), "/"), -1))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fmt.Println(path.Join(apppath, "main.go"))
 | 
						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)), "/"), -1))
 | 
						writetofile(path.Join(apppath, "main.go"), strings.Replace(maingo, "{{.Appname}}", strings.Join(strings.Split(apppath[len(appsrcpath)+1:], string(path.Separator)), "/"), -1))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -135,16 +149,59 @@ runmode = dev
 | 
				
			|||||||
var maingo = `package main
 | 
					var maingo = `package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"{{.Appname}}/controllers"
 | 
						_ "{{.Appname}}/routers"
 | 
				
			||||||
	"github.com/astaxie/beego"
 | 
						"github.com/astaxie/beego"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func main() {
 | 
					func main() {
 | 
				
			||||||
	beego.Router("/", &controllers.MainController{})
 | 
					 | 
				
			||||||
	beego.Run()
 | 
						beego.Run()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
`
 | 
					`
 | 
				
			||||||
 | 
					var router = `package routers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"{{.Appname}}/controllers"
 | 
				
			||||||
 | 
						"github.com/astaxie/beego"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func init() {
 | 
				
			||||||
 | 
					    beego.Router("/", &controllers.MainController{})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var test = `package test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
						"net/http/httptest"
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
						_ "{{.Appname}}/routers"
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
						"github.com/astaxie/beego"
 | 
				
			||||||
 | 
						. "github.com/smartystreets/goconvey/convey"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// TestMain is a sample to run an endpoint test
 | 
				
			||||||
 | 
					func TestMain(t *testing.T) {
 | 
				
			||||||
 | 
						r, _ := http.NewRequest("GET", "/", nil)
 | 
				
			||||||
 | 
						w := httptest.NewRecorder()
 | 
				
			||||||
 | 
						beego.BeeApp.Handlers.ServeHTTP(w, r)
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						beego.Trace("testing", "TestMain", "Code[%d]\n%s", w.Code, w.Body.String())
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						Convey("Subject: Test Station Endpoint\n", t, func() {
 | 
				
			||||||
 | 
						        Convey("Status Code Should Be 200", func() {
 | 
				
			||||||
 | 
						                So(w.Code, ShouldEqual, 200)
 | 
				
			||||||
 | 
						        })
 | 
				
			||||||
 | 
						        Convey("The Result Should Not Be Empty", func() {
 | 
				
			||||||
 | 
						                So(w.Body.Len(), ShouldBeGreaterThan, 0)
 | 
				
			||||||
 | 
						        })
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var controllers = `package controllers
 | 
					var controllers = `package controllers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user