go-zero icon indicating copy to clipboard operation
go-zero copied to clipboard

I hope provide a response interceptor to achieve a common format response

Open zhouyusd opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe. I hope to achieve a common format response, like

type CommonResp struct {
    Code int    `json:"code"`
    Msg  string `json:"msg"`
    Data any    `json:"data"`
}

Describe the solution you'd like

httpx.SetCommonHandlerCtx(func(ctx context.Context, v any) any {
    return CommonResp{
        Code: 20000,
        Msg: "success",
        Data: v,
    }
})

Describe alternatives you've considered I tried to modify handler.tpl, but I found that it was inappropriate to use the same package path of CommonResp.

zhouyusd avatar May 19 '23 17:05 zhouyusd