Closed tangx closed 2 years ago
// output give response code and data
// content-type is text/plain if data is string type, or content-type
// is application/json by default. maybe it will support more
// content types in feture.
func (r *RouterGroup) output(c *gin.Context, data interface{}, err error) {
code, data := extract(data, err)
switch ret := data.(type) {
case string:
c.String(code, ret)
default:
c.JSON(code, ret)
}
}
如果
v.Type()= string
, 则使用c.String()
, 否则使用用c.Json()
如果
err!=nil
优先返回 error