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
8af8936e
Commit
8af8936e
authored
Sep 19, 2015
by
astaxie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1368 from JessonChan/fargo
error bug fixed and clean code
parents
cb0400dc
07a42458
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
12 deletions
+19
-12
beego.go
beego.go
+1
-0
error.go
error.go
+15
-9
router.go
router.go
+3
-3
No files found.
beego.go
View file @
8af8936e
...
...
@@ -40,6 +40,7 @@ func AddAPPStartHook(hf hookfunc) {
// Run beego application.
// beego.Run() default run on HttpPort
// beego.Run("localhost")
// beego.Run(":8089")
// beego.Run("127.0.0.1:8089")
func
Run
(
params
...
string
)
{
...
...
error.go
View file @
8af8936e
...
...
@@ -204,6 +204,7 @@ type errorInfo struct {
}
// map of http handlers for each error string.
// there is 10 kinds default error(40x and 50x)
var
ErrorMaps
=
make
(
map
[
string
]
*
errorInfo
,
10
)
// show 401 unauthorized error.
...
...
@@ -375,13 +376,14 @@ func ErrorController(c ControllerInterface) *App {
rt
:=
reflectVal
.
Type
()
ct
:=
reflect
.
Indirect
(
reflectVal
)
.
Type
()
for
i
:=
0
;
i
<
rt
.
NumMethod
();
i
++
{
if
!
utils
.
InSlice
(
rt
.
Method
(
i
)
.
Name
,
exceptMethod
)
&&
strings
.
HasPrefix
(
rt
.
Method
(
i
)
.
Name
,
"Error"
)
{
methodName
:=
rt
.
Method
(
i
)
.
Name
if
!
utils
.
InSlice
(
methodName
,
exceptMethod
)
&&
strings
.
HasPrefix
(
methodName
,
"Error"
)
{
errinfo
:=
&
errorInfo
{}
errinfo
.
errorType
=
errorTypeController
errinfo
.
controllerType
=
ct
errinfo
.
method
=
rt
.
Method
(
i
)
.
Name
err
name
:=
strings
.
TrimPrefix
(
rt
.
Method
(
i
)
.
Name
,
"Error"
)
ErrorMaps
[
err
n
ame
]
=
errinfo
errinfo
.
method
=
method
Name
err
Name
:=
strings
.
TrimPrefix
(
method
Name
,
"Error"
)
ErrorMaps
[
err
N
ame
]
=
errinfo
}
}
return
BeeApp
...
...
@@ -390,18 +392,22 @@ func ErrorController(c ControllerInterface) *App {
// show error string as simple text message.
// if error string is empty, show 503 or 500 error as default.
func
exception
(
errCode
string
,
ctx
*
context
.
Context
)
{
code
,
_
:=
strconv
.
Atoi
(
errCode
)
if
code
==
0
{
code
=
503
atoi
:=
func
(
code
string
)
int
{
v
,
err
:=
strconv
.
Atoi
(
code
)
if
err
==
nil
{
return
v
}
return
503
}
for
_
,
ec
:=
range
[]
string
{
errCode
,
"503"
,
"500"
}
{
if
h
,
ok
:=
ErrorMaps
[
ec
];
ok
{
executeError
(
h
,
ctx
,
code
)
executeError
(
h
,
ctx
,
atoi
(
ec
)
)
return
}
}
//if 50x error has been removed from errorMap
ctx
.
ResponseWriter
.
WriteHeader
(
code
)
ctx
.
ResponseWriter
.
WriteHeader
(
atoi
(
errCode
)
)
ctx
.
WriteString
(
errCode
)
}
...
...
router.go
View file @
8af8936e
...
...
@@ -108,7 +108,7 @@ type controllerInfo struct {
controllerType
reflect
.
Type
methods
map
[
string
]
string
handler
http
.
Handler
run
f
unction
FilterFunc
run
F
unction
FilterFunc
routerType
int
}
...
...
@@ -324,7 +324,7 @@ func (p *ControllerRegister) AddMethod(method, pattern string, f FilterFunc) {
route
:=
&
controllerInfo
{}
route
.
pattern
=
pattern
route
.
routerType
=
routerTypeRESTFul
route
.
run
f
unction
=
f
route
.
run
F
unction
=
f
methods
:=
make
(
map
[
string
]
string
)
if
method
==
"*"
{
for
_
,
val
:=
range
HTTPMETHOD
{
...
...
@@ -725,7 +725,7 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
if
routerInfo
.
routerType
==
routerTypeRESTFul
{
if
_
,
ok
:=
routerInfo
.
methods
[
r
.
Method
];
ok
{
isRunable
=
true
routerInfo
.
run
f
unction
(
context
)
routerInfo
.
run
F
unction
(
context
)
}
else
{
exception
(
"405"
,
context
)
goto
Admin
...
...
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