| 12345678910111213141516171819202122232425262728293031 |
- package response
- import (
- "github.com/gogf/gf/frame/g"
- "github.com/gogf/gf/net/ghttp"
- )
- type PagedRecords struct {
- Current int `json:"current,omitempty"` //分页当前页
- Total int `json:"total,omitempty"` //结果总数
- Size int `json:"size,omitempty"` //分页记录数条数
- Records interface{} `json:"records,omitempty"` //数据
- }
- // 标准返回结果数据结构封装。
- // 返回固定数据结构的JSON:
- // code: 错误码(0:成功, 1:失败, >1:错误码);
- // msg: 请求结果信息;
- // data: 请求结果,根据不同接口返回结果的数据结构不同;
- func Json(r *ghttp.Request, code int, msg string, data ...interface{}) {
- responseData := interface{}(nil)
- if len(data) > 0 {
- responseData = data[0]
- }
- r.Response.WriteJson(g.Map{
- "code": code,
- "msg": msg,
- "data": responseData,
- })
- r.Exit()
- }
|