예제 #1
0
파일: context.go 프로젝트: opensdk/gin
// 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)
	}
}
예제 #2
0
파일: context.go 프로젝트: opensdk/gin
// 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)
	}
}
예제 #3
0
파일: context.go 프로젝트: opensdk/gin
// 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)
	}
}