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
10e7dc85
authored
2013-01-06 11:25:05 +0800
by
astaxie
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix a bug about json and xml
1 parent
45710c3a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
4 deletions
README.md
controller.go
README.md
View file @
10e7dc8
...
...
@@ -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 @
10e7dc8
...
...
@@ -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
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