示例#1
0
func (r *TextResult) Write(ctx framework.WebContext) error {

	ctx.WriteHeader(http.StatusOK)
	ctx.ContentType("text/plain")
	_, err := ctx.Write([]byte(r.Value))

	return err
}
示例#2
0
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
}
示例#3
0
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
}
示例#4
0
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
}
示例#5
0
func (r *FrameworkErrorResult) Write(ctx framework.WebContext) error {
	//TODO: implement properly
	ctx.Write([]byte("Here goes FrameworkErrorResult: " + r.Err.Error()))
	return nil
}