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
3a5de83e
Commit
3a5de83e
authored
Sep 28, 2014
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
beego: support router case sensitive
parent
f5f33955
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
2 deletions
+21
-2
config.go
config.go
+7
-0
router.go
router.go
+14
-2
No files found.
config.go
View file @
3a5de83e
...
...
@@ -81,6 +81,7 @@ var (
FlashSeperator
string
// used to seperate flash key:value
AppConfigProvider
string
// config provider
EnableDocs
bool
// enable generate docs & server docs API Swagger
RouterCaseSensitive
bool
// router case sensitive default is true
)
func
init
()
{
...
...
@@ -164,6 +165,8 @@ func init() {
FlashName
=
"BEEGO_FLASH"
FlashSeperator
=
"BEEGOFLASH"
RouterCaseSensitive
=
true
runtime
.
GOMAXPROCS
(
runtime
.
NumCPU
())
// init BeeLogger
...
...
@@ -375,6 +378,10 @@ func ParseConfig() (err error) {
if
enabledocs
,
err
:=
GetConfig
(
"bool"
,
"EnableDocs"
);
err
==
nil
{
EnableDocs
=
enabledocs
.
(
bool
)
}
if
casesensitive
,
err
:=
GetConfig
(
"bool"
,
"RouterCaseSensitive"
);
err
==
nil
{
RouterCaseSensitive
=
casesensitive
.
(
bool
)
}
}
return
nil
}
...
...
router.go
View file @
3a5de83e
...
...
@@ -163,6 +163,9 @@ func (p *ControllerRegistor) Add(pattern string, c ControllerInterface, mappingM
}
func
(
p
*
ControllerRegistor
)
addToRouter
(
method
,
pattern
string
,
r
*
controllerInfo
)
{
if
!
RouterCaseSensitive
{
pattern
=
strings
.
ToLower
(
pattern
)
}
if
t
,
ok
:=
p
.
routers
[
method
];
ok
{
t
.
AddRouter
(
pattern
,
r
)
}
else
{
...
...
@@ -381,6 +384,9 @@ func (p *ControllerRegistor) InsertFilter(pattern string, pos int, filter Filter
mr
.
tree
=
NewTree
()
mr
.
pattern
=
pattern
mr
.
filterFunc
=
filter
if
!
RouterCaseSensitive
{
pattern
=
strings
.
ToLower
(
pattern
)
}
mr
.
tree
.
AddRouter
(
pattern
,
true
)
return
p
.
insertFilterRouter
(
pos
,
mr
)
}
...
...
@@ -565,12 +571,18 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
context
.
Output
.
Context
=
context
context
.
Output
.
EnableGzip
=
EnableGzip
var
urlPath
string
if
!
RouterCaseSensitive
{
urlPath
=
strings
.
ToLower
(
r
.
URL
.
Path
)
}
else
{
urlPath
=
r
.
URL
.
Path
}
// defined filter function
do_filter
:=
func
(
pos
int
)
(
started
bool
)
{
if
p
.
enableFilter
{
if
l
,
ok
:=
p
.
filters
[
pos
];
ok
{
for
_
,
filterR
:=
range
l
{
if
ok
,
p
:=
filterR
.
ValidRouter
(
r
.
URL
.
Path
);
ok
{
if
ok
,
p
:=
filterR
.
ValidRouter
(
url
Path
);
ok
{
context
.
Input
.
Params
=
p
filterR
.
filterFunc
(
context
)
if
w
.
started
{
...
...
@@ -628,7 +640,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
if
!
findrouter
{
if
t
,
ok
:=
p
.
routers
[
r
.
Method
];
ok
{
runObject
,
p
:=
t
.
Match
(
r
.
URL
.
Path
)
runObject
,
p
:=
t
.
Match
(
url
Path
)
if
r
,
ok
:=
runObject
.
(
*
controllerInfo
);
ok
{
routerInfo
=
r
findrouter
=
true
...
...
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