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 }
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 *GenericResult) Write(ctx framework.WebContext) error { if r.Status > 0 { ctx.WriteHeader(r.Status) } else { ctx.WriteHeader(http.StatusOK) } if r.Message != "" { ctx.Write([]byte(r.Message)) } return nil }
func (r *FrameworkErrorResult) Write(ctx framework.WebContext) error { //TODO: implement properly ctx.Write([]byte("Here goes FrameworkErrorResult: " + r.Err.Error())) return nil }