func (r *JsonResult) Write(ctx framework.WebContext) error { data, err := json.Marshal(r.Value) if err != nil { return err } ctx.WriteHeader(http.StatusOK) callback, _ := ctx.Param("callback") if callback == "" { //json ctx.ContentType("application/json") _, err = ctx.Write(data) } else { //jsonp ctx.ContentType("application/javascript") _, err = ctx.Write([]byte(fmt.Sprintf(jsonpFormat, callback))) _, err = ctx.Write(data) _, err = ctx.Write(jsonpEnclosing) } return err }
func (r *TextResult) Write(ctx framework.WebContext) error { ctx.WriteHeader(http.StatusOK) ctx.ContentType("text/plain") _, err := ctx.Write([]byte(r.Value)) return err }
func (r *XmlResult) Write(ctx framework.WebContext) error { data, err := xml.Marshal(r.Value) if err == nil { ctx.WriteHeader(http.StatusOK) ctx.ContentType("application/xml") ctx.Write(data) } return err }