0372b817 by astaxie

ServeJson ServeJsonp ServeXml and choice

1 parent a3363b06
...@@ -216,7 +216,13 @@ func (c *Controller) Abort(code string) { ...@@ -216,7 +216,13 @@ func (c *Controller) Abort(code string) {
216 } 216 }
217 217
218 func (c *Controller) ServeJson(encoding ...bool) { 218 func (c *Controller) ServeJson(encoding ...bool) {
219 content, err := json.Marshal(c.Data["json"]) 219 var content []byte
220 var err error
221 if RunMode == "prod" {
222 content, err = json.Marshal(c.Data["json"])
223 } else {
224 content, err = json.MarshalIndent(c.Data["json"], "", " ")
225 }
220 if err != nil { 226 if err != nil {
221 http.Error(c.Ctx.ResponseWriter, err.Error(), http.StatusInternalServerError) 227 http.Error(c.Ctx.ResponseWriter, err.Error(), http.StatusInternalServerError)
222 return 228 return
...@@ -229,7 +235,13 @@ func (c *Controller) ServeJson(encoding ...bool) { ...@@ -229,7 +235,13 @@ func (c *Controller) ServeJson(encoding ...bool) {
229 } 235 }
230 236
231 func (c *Controller) ServeJsonp() { 237 func (c *Controller) ServeJsonp() {
232 content, err := json.Marshal(c.Data["jsonp"]) 238 var content []byte
239 var err error
240 if RunMode == "prod" {
241 content, err = json.Marshal(c.Data["jsonp"])
242 } else {
243 content, err = json.MarshalIndent(c.Data["jsonp"], "", " ")
244 }
233 if err != nil { 245 if err != nil {
234 http.Error(c.Ctx.ResponseWriter, err.Error(), http.StatusInternalServerError) 246 http.Error(c.Ctx.ResponseWriter, err.Error(), http.StatusInternalServerError)
235 return 247 return
...@@ -248,7 +260,13 @@ func (c *Controller) ServeJsonp() { ...@@ -248,7 +260,13 @@ func (c *Controller) ServeJsonp() {
248 } 260 }
249 261
250 func (c *Controller) ServeXml() { 262 func (c *Controller) ServeXml() {
251 content, err := xml.Marshal(c.Data["xml"]) 263 var content []byte
264 var err error
265 if RunMode == "prod" {
266 content, err = xml.Marshal(c.Data["xml"])
267 } else {
268 content, err = xml.MarshalIndent(c.Data["xml"], "", " ")
269 }
252 if err != nil { 270 if err != nil {
253 http.Error(c.Ctx.ResponseWriter, err.Error(), http.StatusInternalServerError) 271 http.Error(c.Ctx.ResponseWriter, err.Error(), http.StatusInternalServerError)
254 return 272 return
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!