Example #1
0
// JSON serializes the given struct as JSON into the response body.
// It also sets the Content-Type as "application/json".
// result is JSONResult, and result success is false
func (c *Context) JSONFailed(obj interface{}, msgs ...string) {
	result := render.JSONResult{Success: true, Data: obj}
	for _, v := range msgs {
		result.Msg += v
	}
	c.writermem.WriteHeader(http.StatusOK)
	if err := render.WriteJSON(c.Writer, result); err != nil {
		c.renderError(err)
	}
}
Example #2
0
// JSON serializes the given struct as JSON into the response body.
// It also sets the Content-Type as "application/json".
// result is JSONResult
func (c *Context) JSONResult(result render.JSONResult) {
	c.writermem.WriteHeader(http.StatusOK)
	if err := render.WriteJSON(c.Writer, result); err != nil {
		c.renderError(err)
	}
}
Example #3
0
// JSON serializes the given struct as JSON into the response body.
// It also sets the Content-Type as "application/json".
func (c *Context) JSON(code int, obj interface{}) {
	c.writermem.WriteHeader(code)
	if err := render.WriteJSON(c.Writer, obj); err != nil {
		c.renderError(err)
	}
}