gf-demo-user icon indicating copy to clipboard operation
gf-demo-user copied to clipboard

新的框架中,如何在 Controller 自定义 status_code ?

Open yangyanqing opened this issue 2 years ago • 0 comments

controller 中没有其他的返回接口,带 error 只能返回 5xx,无法返回 401/403 之类的错误 看调用栈也只是捕获了异常,没有利用 ctx 反向传递结果,请问这种架构下如何自定义返回码呢?

func (c *cUser) SignIn(ctx context.Context, req *v1.UserSignInReq) (res *v1.UserSignInRes, err error) {
	err = service.User().SignIn(ctx, model.UserSignInInput{
		Passport: req.Passport,
		Password: req.Password,
	})
	return
}

yangyanqing avatar May 17 '22 11:05 yangyanqing