Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
31f862c5
authored
2013-12-15 13:17:27 -0500
by
vadimi
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Panic template execution errors to show error pages accordingly
1 parent
505fca93
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
2 deletions
controller.go
router.go
controller.go
View file @
31f862c
...
...
@@ -138,6 +138,7 @@ func (c *Controller) RenderBytes() ([]byte, error) {
err
:=
BeeTemplates
[
c
.
TplNames
]
.
ExecuteTemplate
(
newbytes
,
c
.
TplNames
,
c
.
Data
)
if
err
!=
nil
{
Trace
(
"template Execute err:"
,
err
)
return
nil
,
err
}
tplcontent
,
_
:=
ioutil
.
ReadAll
(
newbytes
)
c
.
Data
[
"LayoutContent"
]
=
template
.
HTML
(
string
(
tplcontent
))
...
...
@@ -145,6 +146,7 @@ func (c *Controller) RenderBytes() ([]byte, error) {
err
=
BeeTemplates
[
c
.
Layout
]
.
ExecuteTemplate
(
ibytes
,
c
.
Layout
,
c
.
Data
)
if
err
!=
nil
{
Trace
(
"template Execute err:"
,
err
)
return
nil
,
err
}
icontent
,
_
:=
ioutil
.
ReadAll
(
ibytes
)
return
icontent
,
nil
...
...
@@ -163,6 +165,7 @@ func (c *Controller) RenderBytes() ([]byte, error) {
err
:=
BeeTemplates
[
c
.
TplNames
]
.
ExecuteTemplate
(
ibytes
,
c
.
TplNames
,
c
.
Data
)
if
err
!=
nil
{
Trace
(
"template Execute err:"
,
err
)
return
nil
,
err
}
icontent
,
_
:=
ioutil
.
ReadAll
(
ibytes
)
return
icontent
,
nil
...
...
router.go
View file @
31f862c
...
...
@@ -26,7 +26,10 @@ const (
FinishRouter
)
var
HTTPMETHOD
=
[]
string
{
"get"
,
"post"
,
"put"
,
"delete"
,
"patch"
,
"options"
,
"head"
}
var
(
HTTPMETHOD
=
[]
string
{
"get"
,
"post"
,
"put"
,
"delete"
,
"patch"
,
"options"
,
"head"
}
errorType
=
reflect
.
TypeOf
((
*
error
)(
nil
))
.
Elem
()
)
type
controllerInfo
struct
{
pattern
string
...
...
@@ -729,7 +732,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
if
!
w
.
started
&&
!
context
.
Input
.
IsWebsocket
()
{
if
AutoRender
{
method
=
vc
.
MethodByName
(
"Render"
)
method
.
Call
(
in
)
callMethodWithError
(
method
,
in
)
}
}
}
...
...
@@ -920,3 +923,15 @@ func (w *responseWriter) WriteHeader(code int) {
w
.
started
=
true
w
.
writer
.
WriteHeader
(
code
)
}
// call method and panic with error if error is in result params
func
callMethodWithError
(
method
reflect
.
Value
,
params
[]
reflect
.
Value
)
{
results
:=
method
.
Call
(
params
)
if
len
(
results
)
>
0
{
for
_
,
result
:=
range
results
{
if
result
.
Type
()
==
errorType
&&
!
result
.
IsNil
()
{
panic
(
result
.
Interface
()
.
(
error
))
}
}
}
}
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
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 post a comment