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
31f505bf
authored
2013-03-14 21:17:37 +0800
by
astaxie
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
add RenderBytes function
1 parent
281747ab
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
3 deletions
controller.go
controller.go
View file @
31f505b
...
...
@@ -83,6 +83,20 @@ func (c *Controller) Options() {
}
func
(
c
*
Controller
)
Render
()
error
{
rb
,
err
:=
c
.
RenderBytes
()
if
err
!=
nil
{
return
err
}
else
{
c
.
Ctx
.
SetHeader
(
"Content-Length"
,
strconv
.
Itoa
(
len
(
rb
)),
true
)
c
.
Ctx
.
ContentType
(
"text/html"
)
c
.
Ctx
.
ResponseWriter
.
Write
(
rb
)
return
nil
}
return
nil
}
func
(
c
*
Controller
)
RenderBytes
()
([]
byte
,
error
)
{
//if the controller has set layout, then first get the tplname's content set the content to the layout
if
c
.
Layout
!=
""
{
if
c
.
TplNames
==
""
{
...
...
@@ -95,22 +109,28 @@ func (c *Controller) Render() error {
tplcontent
,
_
:=
ioutil
.
ReadAll
(
newbytes
)
c
.
Data
[
"LayoutContent"
]
=
template
.
HTML
(
string
(
tplcontent
))
_
,
file
=
path
.
Split
(
c
.
Layout
)
err
:=
BeeTemplates
[
subdir
]
.
ExecuteTemplate
(
c
.
Ctx
.
ResponseWriter
,
file
,
c
.
Data
)
ibytes
:=
bytes
.
NewBufferString
(
""
)
err
:=
BeeTemplates
[
subdir
]
.
ExecuteTemplate
(
ibytes
,
file
,
c
.
Data
)
if
err
!=
nil
{
Trace
(
"template Execute err:"
,
err
)
}
icontent
,
_
:=
ioutil
.
ReadAll
(
ibytes
)
return
icontent
,
nil
}
else
{
if
c
.
TplNames
==
""
{
c
.
TplNames
=
c
.
ChildName
+
"/"
+
c
.
Ctx
.
Request
.
Method
+
"."
+
c
.
TplExt
}
_
,
file
:=
path
.
Split
(
c
.
TplNames
)
subdir
:=
path
.
Dir
(
c
.
TplNames
)
err
:=
BeeTemplates
[
subdir
]
.
ExecuteTemplate
(
c
.
Ctx
.
ResponseWriter
,
file
,
c
.
Data
)
ibytes
:=
bytes
.
NewBufferString
(
""
)
err
:=
BeeTemplates
[
subdir
]
.
ExecuteTemplate
(
ibytes
,
file
,
c
.
Data
)
if
err
!=
nil
{
Trace
(
"template Execute err:"
,
err
)
}
icontent
,
_
:=
ioutil
.
ReadAll
(
ibytes
)
return
icontent
,
nil
}
return
nil
return
[]
byte
{},
nil
}
func
(
c
*
Controller
)
Redirect
(
url
string
,
code
int
)
{
...
...
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