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
06e002cf
Commit
06e002cf
authored
Jun 13, 2013
by
lw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feture: add jsonp
parent
73f0f4f3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
0 deletions
+17
-0
controller.go
controller.go
+17
-0
No files found.
controller.go
View file @
06e002cf
...
...
@@ -216,6 +216,23 @@ func (c *Controller) ServeJson() {
c
.
Ctx
.
ResponseWriter
.
Write
(
content
)
}
func
(
c
*
Controller
)
ServeJsonp
()
{
content
,
err
:=
json
.
MarshalIndent
(
c
.
Data
[
"jsonp"
],
""
,
" "
)
if
err
!=
nil
{
http
.
Error
(
c
.
Ctx
.
ResponseWriter
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
}
callback
:=
c
.
Ctx
.
Request
.
Form
.
Get
(
"callback"
)
if
callback
==
""
{
http
.
Error
(
c
.
Ctx
.
ResponseWriter
,
`"callback" parameter required`
,
http
.
StatusInternalServerError
)
return
}
callback_content
:=
fmt
.
Sprintf
(
"%s(%s);
\r\n
"
,
callback
,
string
(
content
))
c
.
Ctx
.
SetHeader
(
"Content-Length"
,
strconv
.
Itoa
(
len
(
callback_content
)),
true
)
c
.
Ctx
.
ResponseWriter
.
Header
()
.
Set
(
"Content-Type"
,
"application/jsonp;charset=UTF-8"
)
c
.
Ctx
.
ResponseWriter
.
Write
([]
byte
(
callback_content
))
}
func
(
c
*
Controller
)
ServeXml
()
{
content
,
err
:=
xml
.
Marshal
(
c
.
Data
[
"xml"
])
if
err
!=
nil
{
...
...
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