After you setting static directory, when users visit `/images/login/login.png`,Beego accesses `images/login/login.png` in related to your application directory. One more example, if users visit `/static/img/logo.png`, Beego accesses file `public/img/logo.png`.
## 过滤和中间件
beego支持自定义过滤中间件,例如安全验证,强制跳转等
##Filter and middleware
Beego supports customized filter and middleware, such as security verification, force redirect, etc.
如下例子所示,验证用户名是否是admin,应用于全部的请求:
Here is an example of verify user name of all requests, check if it's admin.
var FilterUser = func(w http.ResponseWriter, r *http.Request) {
if r.URL.User == nil || r.URL.User.Username() != "admin" {
This method executes when client sends request as GET method, 403 as default status code. Users overload this method for customized handle process of GET method.
This method executes when client sends request as POST method, 403 as default status code. Users overload this method for customized handle process of POST method.
This method executes when client sends request as DELETE method, 403 as default status code. Users overload this method for customized handle process of DELETE method.
This method executes when client sends request as PUT method, 403 as default status code. Users overload this method for customized handle process of PUT method.
This method executes when client sends request as HEAD method, 403 as default status code. Users overload this method for customized handle process of HEAD method.
This method executes when client sends request as PATCH method, 403 as default status code. Users overload this method for customized handle process of PATCH method.
This method executes when client sends request as OPTIONS method, 403 as default status code. Users overload this method for customized handle process of OPTIONS method.
This method executes after corresponding method finished, empty as default. User overload this method for more usages like close database, clean data, etc.
- Render() error
这个函数主要用来实现渲染模板,如果beego.AutoRender为true的情况下才会执行。
This method is for rendering template, it executes automatically when you set beego.AutoRender to true.
所以通过子struct的方法重写,用户就可以实现自己的逻辑,接下来我们看一个实际的例子:
Overload all methods for all customized logic processes, let's see an example: