mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 07:40:54 +00:00
simplify beego
This commit is contained in:
parent
ad892008cc
commit
d562687868
26
README.md
26
README.md
@ -34,8 +34,8 @@ Here is the canonical "Hello, world" example app for beego:
|
||||
}
|
||||
|
||||
func main() {
|
||||
beego.BeeApp.RegisterController("/", &MainController{})
|
||||
beego.BeeApp.Run()
|
||||
beego.RegisterController("/", &MainController{})
|
||||
beego.Run()
|
||||
}
|
||||
|
||||
default port:8080
|
||||
@ -56,16 +56,16 @@ in other way i has writing a tool to quick create an app based on beego. you can
|
||||
============
|
||||
In beego, a route is a struct paired with a URL-matching pattern. The strcut has many method with the same name of http method to server the http request. Each route is associated with a block:
|
||||
|
||||
beego.BeeApp.RegisterController("/", &controllers.MainController{})
|
||||
beego.BeeApp.RegisterController("/admin", &admin.UserController{})
|
||||
beego.BeeApp.RegisterController("/admin/index", &admin.ArticleController{})
|
||||
beego.BeeApp.RegisterController("/admin/addpkg", &admin.AddController{})
|
||||
beego.RegisterController("/", &controllers.MainController{})
|
||||
beego.RegisterController("/admin", &admin.UserController{})
|
||||
beego.RegisterController("/admin/index", &admin.ArticleController{})
|
||||
beego.RegisterController("/admin/addpkg", &admin.AddController{})
|
||||
|
||||
You can specify custom regular expressions for routes:
|
||||
|
||||
beego.BeeApp.RegisterController("/admin/editpkg/:id([0-9]+)", &admin.EditController{})
|
||||
beego.BeeApp.RegisterController("/admin/delpkg/:id([0-9]+)", &admin.DelController{})
|
||||
beego.BeeApp.RegisterController("/:pkg(.*)", &controllers.MainController{})
|
||||
beego.RegisterController("/admin/editpkg/:id([0-9]+)", &admin.EditController{})
|
||||
beego.RegisterController("/admin/delpkg/:id([0-9]+)", &admin.DelController{})
|
||||
beego.RegisterController("/:pkg(.*)", &controllers.MainController{})
|
||||
|
||||
You can also create routes for static files:
|
||||
|
||||
@ -85,18 +85,18 @@ You can, for example, filter all request to enforce some type of security:
|
||||
}
|
||||
}
|
||||
|
||||
beego.BeeApp.Filter(FilterUser)
|
||||
beego.Filter(FilterUser)
|
||||
|
||||
You can also apply filters only when certain REST URL Parameters exist:
|
||||
|
||||
beego.BeeApp.RegisterController("/:id([0-9]+)", &admin.EditController{})
|
||||
beego.BeeApp.FilterParam("id", func(rw http.ResponseWriter, r *http.Request) {
|
||||
beego.RegisterController("/:id([0-9]+)", &admin.EditController{})
|
||||
beego.FilterParam("id", func(rw http.ResponseWriter, r *http.Request) {
|
||||
...
|
||||
})
|
||||
|
||||
also You can apply filters only when certain prefix URL path exist:
|
||||
|
||||
beego.BeeApp.FilterPrefixPath("/admin", func(rw http.ResponseWriter, r *http.Request) {
|
||||
beego.FilterPrefixPath("/admin", func(rw http.ResponseWriter, r *http.Request) {
|
||||
… auth
|
||||
})
|
||||
|
||||
|
24
beego.go
24
beego.go
@ -125,3 +125,27 @@ func (app *App) ErrorLog(ctx *Context) {
|
||||
func (app *App) AccessLog(ctx *Context) {
|
||||
BeeLogger.Printf("[ACC] host: '%s', request: '%s %s', proto: '%s', ua: %s'', remote: '%s'\n", ctx.Request.Host, ctx.Request.Method, ctx.Request.URL.Path, ctx.Request.Proto, ctx.Request.UserAgent(), ctx.Request.RemoteAddr)
|
||||
}
|
||||
|
||||
func RegisterController(path string, c ControllerInterface) *App {
|
||||
BeeApp.RegisterController(path, c)
|
||||
return BeeApp
|
||||
}
|
||||
|
||||
func Filter(filter http.HandlerFunc) *App {
|
||||
BeeApp.Filter(filter)
|
||||
return BeeApp
|
||||
}
|
||||
|
||||
func FilterParam(param string, filter http.HandlerFunc) *App {
|
||||
BeeApp.FilterParam(param, filter)
|
||||
return BeeApp
|
||||
}
|
||||
|
||||
func FilterPrefixPath(path string, filter http.HandlerFunc) *App {
|
||||
BeeApp.FilterParam(path, filter)
|
||||
return BeeApp
|
||||
}
|
||||
|
||||
func Run() {
|
||||
BeeApp.Run()
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"html/template"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"strconv"
|
||||
)
|
||||
@ -145,3 +146,8 @@ func (c *Controller) ServeXml() {
|
||||
c.Ct.ContentType("xml")
|
||||
c.Ct.ResponseWriter.Write(content)
|
||||
}
|
||||
|
||||
func (c *Controller) Input() url.Values {
|
||||
c.Ct.Request.ParseForm()
|
||||
return c.Ct.Request.Form
|
||||
}
|
||||
|
35
model.go
35
model.go
@ -1 +1,36 @@
|
||||
package beego
|
||||
|
||||
type BeeModel struct {
|
||||
driver string
|
||||
}
|
||||
|
||||
func (this *BeeModel) Insert() {
|
||||
|
||||
}
|
||||
|
||||
func (this *BeeModel) MultipleInsert() {
|
||||
|
||||
}
|
||||
|
||||
func (this *BeeModel) Update() {
|
||||
|
||||
}
|
||||
|
||||
func (this *BeeModel) Query() {
|
||||
|
||||
}
|
||||
|
||||
//Deletes from table with clauses where and using.
|
||||
func (this *BeeModel) Delete() {
|
||||
|
||||
}
|
||||
|
||||
//Start a transaction
|
||||
func (this *BeeModel) Transaction() {
|
||||
|
||||
}
|
||||
|
||||
//commit transaction
|
||||
func (this *BeeModel) Commit() {
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user