simplify beego
Showing
4 changed files
with
78 additions
and
13 deletions
| ... | @@ -34,8 +34,8 @@ Here is the canonical "Hello, world" example app for beego: | ... | @@ -34,8 +34,8 @@ Here is the canonical "Hello, world" example app for beego: |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | func main() { | 36 | func main() { |
| 37 | beego.BeeApp.RegisterController("/", &MainController{}) | 37 | beego.RegisterController("/", &MainController{}) |
| 38 | beego.BeeApp.Run() | 38 | beego.Run() |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | default port:8080 | 41 | 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 | ... | @@ -56,16 +56,16 @@ in other way i has writing a tool to quick create an app based on beego. you can |
| 56 | ============ | 56 | ============ |
| 57 | 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: | 57 | 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: |
| 58 | 58 | ||
| 59 | beego.BeeApp.RegisterController("/", &controllers.MainController{}) | 59 | beego.RegisterController("/", &controllers.MainController{}) |
| 60 | beego.BeeApp.RegisterController("/admin", &admin.UserController{}) | 60 | beego.RegisterController("/admin", &admin.UserController{}) |
| 61 | beego.BeeApp.RegisterController("/admin/index", &admin.ArticleController{}) | 61 | beego.RegisterController("/admin/index", &admin.ArticleController{}) |
| 62 | beego.BeeApp.RegisterController("/admin/addpkg", &admin.AddController{}) | 62 | beego.RegisterController("/admin/addpkg", &admin.AddController{}) |
| 63 | 63 | ||
| 64 | You can specify custom regular expressions for routes: | 64 | You can specify custom regular expressions for routes: |
| 65 | 65 | ||
| 66 | beego.BeeApp.RegisterController("/admin/editpkg/:id([0-9]+)", &admin.EditController{}) | 66 | beego.RegisterController("/admin/editpkg/:id([0-9]+)", &admin.EditController{}) |
| 67 | beego.BeeApp.RegisterController("/admin/delpkg/:id([0-9]+)", &admin.DelController{}) | 67 | beego.RegisterController("/admin/delpkg/:id([0-9]+)", &admin.DelController{}) |
| 68 | beego.BeeApp.RegisterController("/:pkg(.*)", &controllers.MainController{}) | 68 | beego.RegisterController("/:pkg(.*)", &controllers.MainController{}) |
| 69 | 69 | ||
| 70 | You can also create routes for static files: | 70 | You can also create routes for static files: |
| 71 | 71 | ||
| ... | @@ -85,18 +85,18 @@ You can, for example, filter all request to enforce some type of security: | ... | @@ -85,18 +85,18 @@ You can, for example, filter all request to enforce some type of security: |
| 85 | } | 85 | } |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | beego.BeeApp.Filter(FilterUser) | 88 | beego.Filter(FilterUser) |
| 89 | 89 | ||
| 90 | You can also apply filters only when certain REST URL Parameters exist: | 90 | You can also apply filters only when certain REST URL Parameters exist: |
| 91 | 91 | ||
| 92 | beego.BeeApp.RegisterController("/:id([0-9]+)", &admin.EditController{}) | 92 | beego.RegisterController("/:id([0-9]+)", &admin.EditController{}) |
| 93 | beego.BeeApp.FilterParam("id", func(rw http.ResponseWriter, r *http.Request) { | 93 | beego.FilterParam("id", func(rw http.ResponseWriter, r *http.Request) { |
| 94 | ... | 94 | ... |
| 95 | }) | 95 | }) |
| 96 | 96 | ||
| 97 | also You can apply filters only when certain prefix URL path exist: | 97 | also You can apply filters only when certain prefix URL path exist: |
| 98 | 98 | ||
| 99 | beego.BeeApp.FilterPrefixPath("/admin", func(rw http.ResponseWriter, r *http.Request) { | 99 | beego.FilterPrefixPath("/admin", func(rw http.ResponseWriter, r *http.Request) { |
| 100 | … auth | 100 | … auth |
| 101 | }) | 101 | }) |
| 102 | 102 | ... | ... |
| ... | @@ -125,3 +125,27 @@ func (app *App) ErrorLog(ctx *Context) { | ... | @@ -125,3 +125,27 @@ func (app *App) ErrorLog(ctx *Context) { |
| 125 | func (app *App) AccessLog(ctx *Context) { | 125 | func (app *App) AccessLog(ctx *Context) { |
| 126 | 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) | 126 | 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) |
| 127 | } | 127 | } |
| 128 | |||
| 129 | func RegisterController(path string, c ControllerInterface) *App { | ||
| 130 | BeeApp.RegisterController(path, c) | ||
| 131 | return BeeApp | ||
| 132 | } | ||
| 133 | |||
| 134 | func Filter(filter http.HandlerFunc) *App { | ||
| 135 | BeeApp.Filter(filter) | ||
| 136 | return BeeApp | ||
| 137 | } | ||
| 138 | |||
| 139 | func FilterParam(param string, filter http.HandlerFunc) *App { | ||
| 140 | BeeApp.FilterParam(param, filter) | ||
| 141 | return BeeApp | ||
| 142 | } | ||
| 143 | |||
| 144 | func FilterPrefixPath(path string, filter http.HandlerFunc) *App { | ||
| 145 | BeeApp.FilterParam(path, filter) | ||
| 146 | return BeeApp | ||
| 147 | } | ||
| 148 | |||
| 149 | func Run() { | ||
| 150 | BeeApp.Run() | ||
| 151 | } | ... | ... |
| ... | @@ -7,6 +7,7 @@ import ( | ... | @@ -7,6 +7,7 @@ import ( |
| 7 | "html/template" | 7 | "html/template" |
| 8 | "io/ioutil" | 8 | "io/ioutil" |
| 9 | "net/http" | 9 | "net/http" |
| 10 | "net/url" | ||
| 10 | "path" | 11 | "path" |
| 11 | "strconv" | 12 | "strconv" |
| 12 | ) | 13 | ) |
| ... | @@ -145,3 +146,8 @@ func (c *Controller) ServeXml() { | ... | @@ -145,3 +146,8 @@ func (c *Controller) ServeXml() { |
| 145 | c.Ct.ContentType("xml") | 146 | c.Ct.ContentType("xml") |
| 146 | c.Ct.ResponseWriter.Write(content) | 147 | c.Ct.ResponseWriter.Write(content) |
| 147 | } | 148 | } |
| 149 | |||
| 150 | func (c *Controller) Input() url.Values { | ||
| 151 | c.Ct.Request.ParseForm() | ||
| 152 | return c.Ct.Request.Form | ||
| 153 | } | ... | ... |
| 1 | package beego | 1 | package beego |
| 2 | |||
| 3 | type BeeModel struct { | ||
| 4 | driver string | ||
| 5 | } | ||
| 6 | |||
| 7 | func (this *BeeModel) Insert() { | ||
| 8 | |||
| 9 | } | ||
| 10 | |||
| 11 | func (this *BeeModel) MultipleInsert() { | ||
| 12 | |||
| 13 | } | ||
| 14 | |||
| 15 | func (this *BeeModel) Update() { | ||
| 16 | |||
| 17 | } | ||
| 18 | |||
| 19 | func (this *BeeModel) Query() { | ||
| 20 | |||
| 21 | } | ||
| 22 | |||
| 23 | //Deletes from table with clauses where and using. | ||
| 24 | func (this *BeeModel) Delete() { | ||
| 25 | |||
| 26 | } | ||
| 27 | |||
| 28 | //Start a transaction | ||
| 29 | func (this *BeeModel) Transaction() { | ||
| 30 | |||
| 31 | } | ||
| 32 | |||
| 33 | //commit transaction | ||
| 34 | func (this *BeeModel) Commit() { | ||
| 35 | |||
| 36 | } | ... | ... |
-
Please register or sign in to post a comment