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
10e7dc85
Commit
10e7dc85
authored
Jan 06, 2013
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix a bug about json and xml
parent
45710c3a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
4 deletions
+6
-4
README.md
README.md
+4
-2
controller.go
controller.go
+2
-2
No files found.
README.md
View file @
10e7dc85
...
...
@@ -272,14 +272,16 @@ Helper function for serving Json, sets content type to application/json:
```
go
func
(
this
*
AddController
)
Get
()
{
mystruct
:=
{
...
}
routes
.
ServeJson
(
w
,
&
mystruct
)
this
.
Data
[
"json"
]
=
&
mystruct
this
.
ServeJson
()
}
```
Helper function for serving Xml, sets content type to application/xml:
```
go
func
(
this
*
AddController
)
Get
()
{
mystruct
:=
{
...
}
routes
.
ServeXml
(
w
,
&
mystruct
)
this
.
Data
[
"xml"
]
=&
mystruct
this
.
ServeXml
()
}
```
...
...
controller.go
View file @
10e7dc85
...
...
@@ -127,7 +127,7 @@ func (c *Controller) Redirect(url string, code int) {
}
func
(
c
*
Controller
)
ServeJson
()
{
content
,
err
:=
json
.
MarshalIndent
(
c
.
Data
,
""
,
" "
)
content
,
err
:=
json
.
MarshalIndent
(
c
.
Data
[
"json"
]
,
""
,
" "
)
if
err
!=
nil
{
http
.
Error
(
c
.
Ctx
.
ResponseWriter
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
...
...
@@ -138,7 +138,7 @@ func (c *Controller) ServeJson() {
}
func
(
c
*
Controller
)
ServeXml
()
{
content
,
err
:=
xml
.
Marshal
(
c
.
Data
)
content
,
err
:=
xml
.
Marshal
(
c
.
Data
[
"xml"
]
)
if
err
!=
nil
{
http
.
Error
(
c
.
Ctx
.
ResponseWriter
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
...
...
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