mirror of
https://github.com/beego/bee.git
synced 2024-11-21 23:50:54 +00:00
add template
This commit is contained in:
parent
90648d22cd
commit
285e130505
30
apiapp.go
30
apiapp.go
@ -54,6 +54,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
beego.RESTRouter("/object", &controllers.ObejctController{})
|
beego.RESTRouter("/object", &controllers.ObejctController{})
|
||||||
|
beego.Router("/ping", &controllers.ObejctController{},"get:Ping")
|
||||||
beego.Run()
|
beego.Run()
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
@ -170,8 +171,33 @@ func (this *ObejctController) Delete() {
|
|||||||
this.Data["json"] = "delete success!"
|
this.Data["json"] = "delete success!"
|
||||||
this.ServeJson()
|
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() {
|
func init() {
|
||||||
cmdApiapp.Run = createapi
|
cmdApiapp.Run = createapi
|
||||||
}
|
}
|
||||||
@ -205,6 +231,10 @@ func createapi(cmd *Command, args []string) {
|
|||||||
writetofile(path.Join(apppath, "controllers", "default.go"),
|
writetofile(path.Join(apppath, "controllers", "default.go"),
|
||||||
strings.Replace(apiControllers, "{{.Appname}}", packpath, -1))
|
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"))
|
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)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user