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
ea756b68
authored
2013-06-13 02:43:33 -0700
by
astaxie
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge pull request #68 from luw2007/luw2007
feture: add jsonp
2 parents
73f0f4f3
06e002cf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
0 deletions
controller.go
controller.go
View file @
ea756b6
...
...
@@ -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
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