package controller import ( "context" "github.com/gogf/gf/v2/errors/gcode" "github.com/gogf/gf/v2/errors/gerror" "gof_ppw_api/api" "gof_ppw_api/internal/service" ) var Fund = &FundController{} type FundController struct { Controller } // List 基金列表 func (p *FundController) List(ctx context.Context, req *api.FundListReq) (res *api.CommonRes, err error) { data, count, err := service.Fund.List(ctx, req) res = &api.CommonRes{ Data: api.PagerRes{ Data: data, Pager: p.getPager(count, req.Page, req.PageSize), }, } return } // Detail 基金详情 func (p *FundController) Detail(ctx context.Context, req *api.FundDetailReq) (res *api.CommonRes, err error) { data, err := service.Fund.Detail(ctx, req.FundId) res = &api.CommonRes{ Data: data, } return } // Test 自定义错误测试 func (p *FundController) Test(ctx context.Context, req *api.FundTestReq) (res *api.CommonRes, err error) { // g.RequestFromCtx(ctx).Response.WriteJson(data) // 自定义错误代码、错误信息返回 return nil, gerror.NewCode(gcode.New(400, "", nil), "我来报错了-_-") }