1
0
mirror of https://github.com/beego/bee.git synced 2024-11-21 23:50:54 +00:00

change this to short name

This commit is contained in:
astaxie 2014-11-05 22:48:09 +08:00
parent 930049f7de
commit 976602bc01
5 changed files with 80 additions and 80 deletions

View File

@ -303,12 +303,12 @@ type ObjectController struct {
// @Success 200 {string} models.Object.Id
// @Failure 403 body is empty
// @router / [post]
func (this *ObjectController) Post() {
func (o *ObjectController) Post() {
var ob models.Object
json.Unmarshal(this.Ctx.Input.RequestBody, &ob)
json.Unmarshal(o.Ctx.Input.RequestBody, &ob)
objectid := models.AddOne(ob)
this.Data["json"] = map[string]string{"ObjectId": objectid}
this.ServeJson()
o.Data["json"] = map[string]string{"ObjectId": objectid}
o.ServeJson()
}
// @Title Get
@ -317,17 +317,17 @@ func (this *ObjectController) Post() {
// @Success 200 {object} models.Object
// @Failure 403 :objectId is empty
// @router /:objectId [get]
func (this *ObjectController) Get() {
objectId := this.Ctx.Input.Params[":objectId"]
func (o *ObjectController) Get() {
objectId := o.Ctx.Input.Params[":objectId"]
if objectId != "" {
ob, err := models.GetOne(objectId)
if err != nil {
this.Data["json"] = err
o.Data["json"] = err
} else {
this.Data["json"] = ob
o.Data["json"] = ob
}
}
this.ServeJson()
o.ServeJson()
}
// @Title GetAll
@ -335,10 +335,10 @@ func (this *ObjectController) Get() {
// @Success 200 {object} models.Object
// @Failure 403 :objectId is empty
// @router / [get]
func (this *ObjectController) GetAll() {
func (o *ObjectController) GetAll() {
obs := models.GetAll()
this.Data["json"] = obs
this.ServeJson()
o.Data["json"] = obs
o.ServeJson()
}
// @Title update
@ -348,18 +348,18 @@ func (this *ObjectController) GetAll() {
// @Success 200 {object} models.Object
// @Failure 403 :objectId is empty
// @router /:objectId [put]
func (this *ObjectController) Put() {
objectId := this.Ctx.Input.Params[":objectId"]
func (o *ObjectController) Put() {
objectId := o.Ctx.Input.Params[":objectId"]
var ob models.Object
json.Unmarshal(this.Ctx.Input.RequestBody, &ob)
json.Unmarshal(o.Ctx.Input.RequestBody, &ob)
err := models.Update(objectId, ob.Score)
if err != nil {
this.Data["json"] = err
o.Data["json"] = err
} else {
this.Data["json"] = "update success!"
o.Data["json"] = "update success!"
}
this.ServeJson()
o.ServeJson()
}
// @Title delete
@ -368,11 +368,11 @@ func (this *ObjectController) Put() {
// @Success 200 {string} delete success!
// @Failure 403 objectId is empty
// @router /:objectId [delete]
func (this *ObjectController) Delete() {
objectId := this.Ctx.Input.Params[":objectId"]
func (o *ObjectController) Delete() {
objectId := o.Ctx.Input.Params[":objectId"]
models.Delete(objectId)
this.Data["json"] = "delete success!"
this.ServeJson()
o.Data["json"] = "delete success!"
o.ServeJson()
}
`

View File

@ -1147,12 +1147,12 @@ type {{ctrlName}}Controller struct {
beego.Controller
}
func (this *{{ctrlName}}Controller) URLMapping() {
this.Mapping("Post", this.Post)
this.Mapping("GetOne", this.GetOne)
this.Mapping("GetAll", this.GetAll)
this.Mapping("Put", this.Put)
this.Mapping("Delete", this.Delete)
func (c *{{ctrlName}}Controller) URLMapping() {
c.Mapping("Post", c.Post)
c.Mapping("GetOne", c.GetOne)
c.Mapping("GetAll", c.GetAll)
c.Mapping("Put", c.Put)
c.Mapping("Delete", c.Delete)
}
// @Title Post
@ -1161,15 +1161,15 @@ func (this *{{ctrlName}}Controller) URLMapping() {
// @Success 200 {int} models.{{ctrlName}}.Id
// @Failure 403 body is empty
// @router / [post]
func (this *{{ctrlName}}Controller) Post() {
func (c *{{ctrlName}}Controller) Post() {
var v models.{{ctrlName}}
json.Unmarshal(this.Ctx.Input.RequestBody, &v)
json.Unmarshal(c.Ctx.Input.RequestBody, &v)
if id, err := models.Add{{ctrlName}}(&v); err == nil {
this.Data["json"] = map[string]int64{"id": id}
c.Data["json"] = map[string]int64{"id": id}
} else {
this.Data["json"] = err.Error()
c.Data["json"] = err.Error()
}
this.ServeJson()
c.ServeJson()
}
// @Title Get
@ -1178,16 +1178,16 @@ func (this *{{ctrlName}}Controller) Post() {
// @Success 200 {object} models.{{ctrlName}}
// @Failure 403 :id is empty
// @router /:id [get]
func (this *{{ctrlName}}Controller) GetOne() {
idStr := this.Ctx.Input.Params[":id"]
func (c *{{ctrlName}}Controller) GetOne() {
idStr := c.Ctx.Input.Params[":id"]
id, _ := strconv.Atoi(idStr)
v, err := models.Get{{ctrlName}}ById(id)
if err != nil {
this.Data["json"] = err.Error()
c.Data["json"] = err.Error()
} else {
this.Data["json"] = v
c.Data["json"] = v
}
this.ServeJson()
c.ServeJson()
}
// @Title Get All
@ -1201,7 +1201,7 @@ func (this *{{ctrlName}}Controller) GetOne() {
// @Success 200 {object} models.{{ctrlName}}
// @Failure 403
// @router / [get]
func (this *{{ctrlName}}Controller) GetAll() {
func (c *{{ctrlName}}Controller) GetAll() {
var fields []string
var sortby []string
var order []string
@ -1210,32 +1210,32 @@ func (this *{{ctrlName}}Controller) GetAll() {
var offset int64 = 0
// fields: col1,col2,entity.col3
if v := this.GetString("fields"); v != "" {
if v := c.GetString("fields"); v != "" {
fields = strings.Split(v, ",")
}
// limit: 10 (default is 10)
if v, err := this.GetInt64("limit"); err == nil {
if v, err := c.GetInt64("limit"); err == nil {
limit = v
}
// offset: 0 (default is 0)
if v, err := this.GetInt64("offset"); err == nil {
if v, err := c.GetInt64("offset"); err == nil {
offset = v
}
// sortby: col1,col2
if v := this.GetString("sortby"); v != "" {
if v := c.GetString("sortby"); v != "" {
sortby = strings.Split(v, ",")
}
// order: desc,asc
if v := this.GetString("order"); v != "" {
if v := c.GetString("order"); v != "" {
order = strings.Split(v, ",")
}
// query: k:v,k:v
if v := this.GetString("query"); v != "" {
if v := c.GetString("query"); v != "" {
for _, cond := range strings.Split(v, ",") {
kv := strings.Split(cond, ":")
if len(kv) != 2 {
this.Data["json"] = errors.New("Error: invalid query key/value pair")
this.ServeJson()
c.Data["json"] = errors.New("Error: invalid query key/value pair")
c.ServeJson()
return
}
k, v := kv[0], kv[1]
@ -1245,11 +1245,11 @@ func (this *{{ctrlName}}Controller) GetAll() {
l, err := models.GetAll{{ctrlName}}(query, fields, sortby, order, offset, limit)
if err != nil {
this.Data["json"] = err.Error()
c.Data["json"] = err.Error()
} else {
this.Data["json"] = l
c.Data["json"] = l
}
this.ServeJson()
c.ServeJson()
}
// @Title Update
@ -1259,17 +1259,17 @@ func (this *{{ctrlName}}Controller) GetAll() {
// @Success 200 {object} models.{{ctrlName}}
// @Failure 403 :id is not int
// @router /:id [put]
func (this *{{ctrlName}}Controller) Put() {
idStr := this.Ctx.Input.Params[":id"]
func (c *{{ctrlName}}Controller) Put() {
idStr := c.Ctx.Input.Params[":id"]
id, _ := strconv.Atoi(idStr)
v := models.{{ctrlName}}{Id: id}
json.Unmarshal(this.Ctx.Input.RequestBody, &v)
json.Unmarshal(c.Ctx.Input.RequestBody, &v)
if err := models.Update{{ctrlName}}ById(&v); err == nil {
this.Data["json"] = "OK"
c.Data["json"] = "OK"
} else {
this.Data["json"] = err.Error()
c.Data["json"] = err.Error()
}
this.ServeJson()
c.ServeJson()
}
// @Title Delete
@ -1278,15 +1278,15 @@ func (this *{{ctrlName}}Controller) Put() {
// @Success 200 {string} delete success!
// @Failure 403 id is empty
// @router /:id [delete]
func (this *{{ctrlName}}Controller) Delete() {
idStr := this.Ctx.Input.Params[":id"]
func (c *{{ctrlName}}Controller) Delete() {
idStr := c.Ctx.Input.Params[":id"]
id, _ := strconv.Atoi(idStr)
if err := models.Delete{{ctrlName}}(id); err == nil {
this.Data["json"] = "OK"
c.Data["json"] = "OK"
} else {
this.Data["json"] = err.Error()
c.Data["json"] = err.Error()
}
this.ServeJson()
c.ServeJson()
}
`
ROUTER_TPL = `// @APIVersion 1.0.0

View File

@ -68,12 +68,12 @@ type {{controllerName}}Controller struct {
beego.Controller
}
func (this *{{controllerName}}Controller) URLMapping() {
this.Mapping("Post", this.Post)
this.Mapping("GetOne", this.GetOne)
this.Mapping("GetAll", this.GetAll)
this.Mapping("Put", this.Put)
this.Mapping("Delete", this.Delete)
func (c *{{controllerName}}Controller) URLMapping() {
c.Mapping("Post", c.Post)
c.Mapping("GetOne", c.GetOne)
c.Mapping("GetAll", c.GetAll)
c.Mapping("Put", c.Put)
c.Mapping("Delete", c.Delete)
}
// @Title Post
@ -82,7 +82,7 @@ func (this *{{controllerName}}Controller) URLMapping() {
// @Success 200 {int} models.{{controllerName}}.Id
// @Failure 403 body is empty
// @router / [post]
func (this *{{controllerName}}Controller) Post() {
func (c *{{controllerName}}Controller) Post() {
}
@ -92,7 +92,7 @@ func (this *{{controllerName}}Controller) Post() {
// @Success 200 {object} models.{{controllerName}}
// @Failure 403 :id is empty
// @router /:id [get]
func (this *{{controllerName}}Controller) GetOne() {
func (c *{{controllerName}}Controller) GetOne() {
}
@ -107,7 +107,7 @@ func (this *{{controllerName}}Controller) GetOne() {
// @Success 200 {object} models.{{controllerName}}
// @Failure 403
// @router / [get]
func (this *{{controllerName}}Controller) GetAll() {
func (c *{{controllerName}}Controller) GetAll() {
}
@ -118,7 +118,7 @@ func (this *{{controllerName}}Controller) GetAll() {
// @Success 200 {object} models.{{controllerName}}
// @Failure 403 :id is not int
// @router /:id [put]
func (this *{{controllerName}}Controller) Put() {
func (c *{{controllerName}}Controller) Put() {
}
@ -128,7 +128,7 @@ func (this *{{controllerName}}Controller) Put() {
// @Success 200 {string} delete success!
// @Failure 403 id is empty
// @router /:id [delete]
func (this *{{controllerName}}Controller) Delete() {
func (c *{{controllerName}}Controller) Delete() {
}
`

8
new.go
View File

@ -222,10 +222,10 @@ type MainController struct {
beego.Controller
}
func (this *MainController) Get() {
this.Data["Website"] = "beego.me"
this.Data["Email"] = "astaxie@gmail.com"
this.TplNames = "index.tpl"
func (c *MainController) Get() {
c.Data["Website"] = "beego.me"
c.Data["Email"] = "astaxie@gmail.com"
c.TplNames = "index.tpl"
}
`

View File

@ -8,21 +8,21 @@ type Router struct {
beego.Controller
}
func (this *Router) Get() {
func (r *Router) Get() {
}
func (this *Router) Post() {
func (r *Router) Post() {
}
type Controller struct {
}
func (this *Controller) Put() {
func (c *Controller) Put() {
}
func (this *Controller) Delete() {
func (c *Controller) Delete() {
}