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
7dc89911
Commit
7dc89911
authored
Oct 23, 2017
by
astaxie
Committed by
GitHub
Oct 23, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2894 from skOak/develop
add custom middleware options for beego.Run()
parents
b169ea4b
e91afb19
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
1 deletion
+23
-1
app.go
app.go
+9
-1
beego.go
beego.go
+14
-0
No files found.
app.go
View file @
7dc89911
...
...
@@ -51,8 +51,10 @@ func NewApp() *App {
return
app
}
type
MiddleWare
func
(
http
.
Handler
)
http
.
Handler
// Run beego application.
func
(
app
*
App
)
Run
()
{
func
(
app
*
App
)
Run
(
mws
...
MiddleWare
)
{
addr
:=
BConfig
.
Listen
.
HTTPAddr
if
BConfig
.
Listen
.
HTTPPort
!=
0
{
...
...
@@ -94,6 +96,12 @@ func (app *App) Run() {
}
app
.
Server
.
Handler
=
app
.
Handlers
for
i
:=
len
(
mws
)
-
1
;
i
>=
0
;
i
--
{
if
mws
[
i
]
==
nil
{
continue
}
app
.
Server
.
Handler
=
mws
[
i
](
app
.
Server
.
Handler
)
}
app
.
Server
.
ReadTimeout
=
time
.
Duration
(
BConfig
.
Listen
.
ServerTimeOut
)
*
time
.
Second
app
.
Server
.
WriteTimeout
=
time
.
Duration
(
BConfig
.
Listen
.
ServerTimeOut
)
*
time
.
Second
app
.
Server
.
ErrorLog
=
logs
.
GetLogger
(
"HTTP"
)
...
...
beego.go
View file @
7dc89911
...
...
@@ -67,6 +67,20 @@ func Run(params ...string) {
BeeApp
.
Run
()
}
func
RunWithMiddleWares
(
addr
string
,
mws
...
MiddleWare
)
{
initBeforeHTTPRun
()
strs
:=
strings
.
Split
(
addr
,
":"
)
if
len
(
strs
)
>
0
&&
strs
[
0
]
!=
""
{
BConfig
.
Listen
.
HTTPAddr
=
strs
[
0
]
}
if
len
(
strs
)
>
1
&&
strs
[
1
]
!=
""
{
BConfig
.
Listen
.
HTTPPort
,
_
=
strconv
.
Atoi
(
strs
[
1
])
}
BeeApp
.
Run
(
mws
...
)
}
func
initBeforeHTTPRun
()
{
//init hooks
AddAPPStartHook
(
...
...
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