go-zero
go-zero copied to clipboard
I hope provide a response interceptor to achieve a common format response
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.