Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
c1cac160
Commit
c1cac160
authored
Dec 15, 2012
by
xiemengjun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加了文档和router函数
parent
9e428ba9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
0 deletions
+39
-0
README.md
README.md
+24
-0
beego.go
beego.go
+15
-0
No files found.
README.md
View file @
c1cac160
...
@@ -72,5 +72,28 @@ this will serve any files in /static, including files in subdirectories. For exa
...
@@ -72,5 +72,28 @@ this will serve any files in /static, including files in subdirectories. For exa
## Filters / Middleware
## Filters / Middleware
============
============
You can apply filters to routes, which is useful for enforcing security, redirects, etc.
You can, for example, filter all request to enforce some type of security:
var FilterUser = func(w http.ResponseWriter, r *http.Request) {
if r.URL.User == nil || r.URL.User.Username() != "admin" {
http.Error(w, "", http.StatusUnauthorized)
}
}
beego.BeeApp.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) {
...
})
also You can apply filters only when certain prefix URL path exist:
beego.BeeApp.FilterPrefixPath("/admin", func(rw http.ResponseWriter, r *http.Request) {
… auth
})
\ No newline at end of file
beego.go
View file @
c1cac160
...
@@ -93,6 +93,21 @@ func (app *App) RegisterController(path string, c ControllerInterface) *App {
...
@@ -93,6 +93,21 @@ func (app *App) RegisterController(path string, c ControllerInterface) *App {
return
app
return
app
}
}
func
(
app
*
App
)
Filter
(
filter
http
.
HandlerFunc
)
*
App
{
app
.
Handlers
.
Filter
(
filter
)
return
app
}
func
(
app
*
App
)
FilterParam
(
param
string
,
filter
http
.
HandlerFunc
)
*
App
{
app
.
Handlers
.
FilterParam
(
param
,
filter
)
return
app
}
func
(
app
*
App
)
FilterPrefixPath
(
path
string
,
filter
http
.
HandlerFunc
)
*
App
{
app
.
Handlers
.
FilterParam
(
path
,
filter
)
return
app
}
func
(
app
*
App
)
SetViewsPath
(
path
string
)
*
App
{
func
(
app
*
App
)
SetViewsPath
(
path
string
)
*
App
{
ViewsPath
=
path
ViewsPath
=
path
return
app
return
app
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment