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
cd514803
Commit
cd514803
authored
Dec 22, 2015
by
fud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplify filter.go hooks.go
parent
2ddda596
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
24 deletions
+30
-24
filter.go
filter.go
+5
-6
hooks.go
hooks.go
+25
-18
No files found.
filter.go
View file @
cd514803
...
...
@@ -33,12 +33,11 @@ type FilterRouter struct {
// If the request is matched, the values of the URL parameters defined
// by the filter pattern are also returned.
func
(
f
*
FilterRouter
)
ValidRouter
(
url
string
,
ctx
*
context
.
Context
)
bool
{
isok
:=
f
.
tree
.
Match
(
url
,
ctx
)
if
isok
==
nil
{
return
false
}
if
isok
,
ok
:=
isok
.
(
bool
);
ok
{
return
isok
isOk
:=
f
.
tree
.
Match
(
url
,
ctx
)
if
isOk
!=
nil
{
if
b
,
ok
:=
isOk
.
(
bool
);
ok
{
return
b
}
}
return
false
}
hooks.go
View file @
cd514803
package
beego
import
(
"encoding/json"
"mime"
"path/filepath"
"strconv"
"net/http"
"path/filepath"
"github.com/astaxie/beego/session"
)
...
...
@@ -20,8 +19,7 @@ func registerMime() error {
// register default error http handlers, 404,401,403,500 and 503.
func
registerDefaultErrorHandler
()
error
{
for
e
,
h
:=
range
map
[
string
]
func
(
http
.
ResponseWriter
,
*
http
.
Request
){
m
:=
map
[
string
]
func
(
http
.
ResponseWriter
,
*
http
.
Request
){
"401"
:
unauthorized
,
"402"
:
paymentRequired
,
"403"
:
forbidden
,
...
...
@@ -32,7 +30,8 @@ func registerDefaultErrorHandler() error {
"502"
:
badGateway
,
"503"
:
serviceUnavailable
,
"504"
:
gatewayTimeout
,
}
{
}
for
e
,
h
:=
range
m
{
if
_
,
ok
:=
ErrorMaps
[
e
];
!
ok
{
ErrorHandler
(
e
,
h
)
}
...
...
@@ -45,16 +44,22 @@ func registerSession() error {
var
err
error
sessionConfig
:=
AppConfig
.
String
(
"sessionConfig"
)
if
sessionConfig
==
""
{
sessionConfig
=
`{"cookieName":"`
+
BConfig
.
WebConfig
.
Session
.
SessionName
+
`",`
+
`"gclifetime":`
+
strconv
.
FormatInt
(
BConfig
.
WebConfig
.
Session
.
SessionGCMaxLifetime
,
10
)
+
`,`
+
`"providerConfig":"`
+
filepath
.
ToSlash
(
BConfig
.
WebConfig
.
Session
.
SessionProviderConfig
)
+
`",`
+
`"secure":`
+
strconv
.
FormatBool
(
BConfig
.
Listen
.
HTTPSEnable
)
+
`,`
+
`"enableSetCookie":`
+
strconv
.
FormatBool
(
BConfig
.
WebConfig
.
Session
.
SessionAutoSetCookie
)
+
`,`
+
`"domain":"`
+
BConfig
.
WebConfig
.
Session
.
SessionDomain
+
`",`
+
`"cookieLifeTime":`
+
strconv
.
Itoa
(
BConfig
.
WebConfig
.
Session
.
SessionCookieLifeTime
)
+
`}`
conf
:=
map
[
string
]
interface
{}{
"cookieName"
:
BConfig
.
WebConfig
.
Session
.
SessionName
,
"gclifetime"
:
BConfig
.
WebConfig
.
Session
.
SessionGCMaxLifetime
,
"providerConfig"
:
filepath
.
ToSlash
(
BConfig
.
WebConfig
.
Session
.
SessionProviderConfig
),
"secure"
:
BConfig
.
Listen
.
HTTPSEnable
,
"enableSetCookie"
:
BConfig
.
WebConfig
.
Session
.
SessionAutoSetCookie
,
"domain"
:
BConfig
.
WebConfig
.
Session
.
SessionDomain
,
"cookieLifeTime"
:
BConfig
.
WebConfig
.
Session
.
SessionCookieLifeTime
,
}
confBytes
,
err
:=
json
.
Marshal
(
conf
)
if
err
!=
nil
{
return
err
}
sessionConfig
=
string
(
confBytes
)
}
GlobalSessions
,
err
=
session
.
NewManager
(
BConfig
.
WebConfig
.
Session
.
SessionProvider
,
sessionConfig
)
if
err
!=
nil
{
if
GlobalSessions
,
err
=
session
.
NewManager
(
BConfig
.
WebConfig
.
Session
.
SessionProvider
,
sessionConfig
);
err
!=
nil
{
return
err
}
go
GlobalSessions
.
GC
()
...
...
@@ -64,9 +69,11 @@ func registerSession() error {
func
registerTemplate
()
error
{
if
BConfig
.
WebConfig
.
AutoRender
{
err
:=
BuildTemplate
(
BConfig
.
WebConfig
.
ViewsPath
)
if
err
!=
nil
&&
BConfig
.
RunMode
==
"dev"
{
Warn
(
err
)
if
err
:=
BuildTemplate
(
BConfig
.
WebConfig
.
ViewsPath
);
err
!=
nil
{
if
BConfig
.
RunMode
==
"dev"
{
Warn
(
err
)
}
return
err
}
}
return
nil
...
...
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