mirror of
https://github.com/zhufuyi/sponge.git
synced 2025-10-05 08:46:57 +08:00
wrap ctx
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Code generated by https://github.com/zhufuyi/sponge/tree/main/cmd/protoc-gen-go-gin, DO NOT EDIT.
|
||||
// Code generated by https://github.com/zhufuyi/sponge, DO NOT EDIT.
|
||||
|
||||
package v1
|
||||
|
||||
@@ -31,6 +31,7 @@ type userExampleServiceOptions struct {
|
||||
zapLog *zap.Logger
|
||||
httpErrors []*errcode.Error
|
||||
rpcStatus []*errcode.RPCStatus
|
||||
wrapCtxFn func(c *gin.Context) context.Context
|
||||
}
|
||||
|
||||
func (o *userExampleServiceOptions) apply(opts ...UserExampleServiceOption) {
|
||||
@@ -75,6 +76,12 @@ func WithUserExampleServiceRPCStatusToHTTPCode(s ...*errcode.RPCStatus) UserExam
|
||||
}
|
||||
}
|
||||
|
||||
func WithUserExampleServiceWrapCtx(wrapCtxFn func(c *gin.Context) context.Context) UserExampleServiceOption {
|
||||
return func(o *userExampleServiceOptions) {
|
||||
o.wrapCtxFn = wrapCtxFn
|
||||
}
|
||||
}
|
||||
|
||||
func RegisterUserExampleServiceRouter(
|
||||
iRouter gin.IRouter,
|
||||
groupPathMiddlewares map[string][]gin.HandlerFunc,
|
||||
@@ -99,6 +106,7 @@ func RegisterUserExampleServiceRouter(
|
||||
iLogic: iLogic,
|
||||
iResponse: o.responser,
|
||||
zapLog: o.zapLog,
|
||||
wrapCtxFn: o.wrapCtxFn,
|
||||
}
|
||||
r.register()
|
||||
}
|
||||
@@ -110,6 +118,7 @@ type userExampleServiceRouter struct {
|
||||
iLogic UserExampleServiceLogicer
|
||||
iResponse errcode.Responser
|
||||
zapLog *zap.Logger
|
||||
wrapCtxFn func(c *gin.Context) context.Context
|
||||
}
|
||||
|
||||
func (r *userExampleServiceRouter) register() {
|
||||
@@ -152,19 +161,24 @@ func (r *userExampleServiceRouter) withMiddleware(method string, path string, fn
|
||||
|
||||
func (r *userExampleServiceRouter) Create_0(c *gin.Context) {
|
||||
req := &CreateUserExampleRequest{}
|
||||
var err error
|
||||
|
||||
if err := c.ShouldBindJSON(req); err != nil {
|
||||
if err = c.ShouldBindJSON(req); err != nil {
|
||||
r.zapLog.Warn("ShouldBindJSON error", zap.Error(err), middleware.GCtxRequestIDField(c))
|
||||
r.iResponse.ParamError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
out, err := r.iLogic.Create(c.Request.Context(), req)
|
||||
var ctx context.Context
|
||||
if r.wrapCtxFn != nil {
|
||||
ctx = r.wrapCtxFn(c)
|
||||
} else {
|
||||
ctx = c
|
||||
}
|
||||
|
||||
out, err := r.iLogic.Create(ctx, req)
|
||||
if err != nil {
|
||||
isIgnore := r.iResponse.Error(c, err)
|
||||
if !isIgnore {
|
||||
r.zapLog.Error("Create error", zap.Error(err), middleware.GCtxRequestIDField(c))
|
||||
}
|
||||
r.iResponse.Error(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -173,25 +187,30 @@ func (r *userExampleServiceRouter) Create_0(c *gin.Context) {
|
||||
|
||||
func (r *userExampleServiceRouter) DeleteByID_0(c *gin.Context) {
|
||||
req := &DeleteUserExampleByIDRequest{}
|
||||
var err error
|
||||
|
||||
if err := c.ShouldBindUri(req); err != nil {
|
||||
if err = c.ShouldBindUri(req); err != nil {
|
||||
r.zapLog.Warn("ShouldBindUri error", zap.Error(err), middleware.GCtxRequestIDField(c))
|
||||
r.iResponse.ParamError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.ShouldBindQuery(req); err != nil {
|
||||
if err = c.ShouldBindQuery(req); err != nil {
|
||||
r.zapLog.Warn("ShouldBindQuery error", zap.Error(err), middleware.GCtxRequestIDField(c))
|
||||
r.iResponse.ParamError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
out, err := r.iLogic.DeleteByID(c.Request.Context(), req)
|
||||
var ctx context.Context
|
||||
if r.wrapCtxFn != nil {
|
||||
ctx = r.wrapCtxFn(c)
|
||||
} else {
|
||||
ctx = c
|
||||
}
|
||||
|
||||
out, err := r.iLogic.DeleteByID(ctx, req)
|
||||
if err != nil {
|
||||
isIgnore := r.iResponse.Error(c, err)
|
||||
if !isIgnore {
|
||||
r.zapLog.Error("DeleteByID error", zap.Error(err), middleware.GCtxRequestIDField(c))
|
||||
}
|
||||
r.iResponse.Error(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -200,19 +219,24 @@ func (r *userExampleServiceRouter) DeleteByID_0(c *gin.Context) {
|
||||
|
||||
func (r *userExampleServiceRouter) DeleteByIDs_0(c *gin.Context) {
|
||||
req := &DeleteUserExampleByIDsRequest{}
|
||||
var err error
|
||||
|
||||
if err := c.ShouldBindJSON(req); err != nil {
|
||||
if err = c.ShouldBindJSON(req); err != nil {
|
||||
r.zapLog.Warn("ShouldBindJSON error", zap.Error(err), middleware.GCtxRequestIDField(c))
|
||||
r.iResponse.ParamError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
out, err := r.iLogic.DeleteByIDs(c.Request.Context(), req)
|
||||
var ctx context.Context
|
||||
if r.wrapCtxFn != nil {
|
||||
ctx = r.wrapCtxFn(c)
|
||||
} else {
|
||||
ctx = c
|
||||
}
|
||||
|
||||
out, err := r.iLogic.DeleteByIDs(ctx, req)
|
||||
if err != nil {
|
||||
isIgnore := r.iResponse.Error(c, err)
|
||||
if !isIgnore {
|
||||
r.zapLog.Error("DeleteByIDs error", zap.Error(err), middleware.GCtxRequestIDField(c))
|
||||
}
|
||||
r.iResponse.Error(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -221,25 +245,30 @@ func (r *userExampleServiceRouter) DeleteByIDs_0(c *gin.Context) {
|
||||
|
||||
func (r *userExampleServiceRouter) UpdateByID_0(c *gin.Context) {
|
||||
req := &UpdateUserExampleByIDRequest{}
|
||||
var err error
|
||||
|
||||
if err := c.ShouldBindUri(req); err != nil {
|
||||
if err = c.ShouldBindUri(req); err != nil {
|
||||
r.zapLog.Warn("ShouldBindUri error", zap.Error(err), middleware.GCtxRequestIDField(c))
|
||||
r.iResponse.ParamError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.ShouldBindJSON(req); err != nil {
|
||||
if err = c.ShouldBindJSON(req); err != nil {
|
||||
r.zapLog.Warn("ShouldBindJSON error", zap.Error(err), middleware.GCtxRequestIDField(c))
|
||||
r.iResponse.ParamError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
out, err := r.iLogic.UpdateByID(c.Request.Context(), req)
|
||||
var ctx context.Context
|
||||
if r.wrapCtxFn != nil {
|
||||
ctx = r.wrapCtxFn(c)
|
||||
} else {
|
||||
ctx = c
|
||||
}
|
||||
|
||||
out, err := r.iLogic.UpdateByID(ctx, req)
|
||||
if err != nil {
|
||||
isIgnore := r.iResponse.Error(c, err)
|
||||
if !isIgnore {
|
||||
r.zapLog.Error("UpdateByID error", zap.Error(err), middleware.GCtxRequestIDField(c))
|
||||
}
|
||||
r.iResponse.Error(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -248,25 +277,30 @@ func (r *userExampleServiceRouter) UpdateByID_0(c *gin.Context) {
|
||||
|
||||
func (r *userExampleServiceRouter) GetByID_0(c *gin.Context) {
|
||||
req := &GetUserExampleByIDRequest{}
|
||||
var err error
|
||||
|
||||
if err := c.ShouldBindUri(req); err != nil {
|
||||
if err = c.ShouldBindUri(req); err != nil {
|
||||
r.zapLog.Warn("ShouldBindUri error", zap.Error(err), middleware.GCtxRequestIDField(c))
|
||||
r.iResponse.ParamError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.ShouldBindQuery(req); err != nil {
|
||||
if err = c.ShouldBindQuery(req); err != nil {
|
||||
r.zapLog.Warn("ShouldBindQuery error", zap.Error(err), middleware.GCtxRequestIDField(c))
|
||||
r.iResponse.ParamError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
out, err := r.iLogic.GetByID(c.Request.Context(), req)
|
||||
var ctx context.Context
|
||||
if r.wrapCtxFn != nil {
|
||||
ctx = r.wrapCtxFn(c)
|
||||
} else {
|
||||
ctx = c
|
||||
}
|
||||
|
||||
out, err := r.iLogic.GetByID(ctx, req)
|
||||
if err != nil {
|
||||
isIgnore := r.iResponse.Error(c, err)
|
||||
if !isIgnore {
|
||||
r.zapLog.Error("GetByID error", zap.Error(err), middleware.GCtxRequestIDField(c))
|
||||
}
|
||||
r.iResponse.Error(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -275,19 +309,24 @@ func (r *userExampleServiceRouter) GetByID_0(c *gin.Context) {
|
||||
|
||||
func (r *userExampleServiceRouter) ListByIDs_0(c *gin.Context) {
|
||||
req := &ListUserExampleByIDsRequest{}
|
||||
var err error
|
||||
|
||||
if err := c.ShouldBindJSON(req); err != nil {
|
||||
if err = c.ShouldBindJSON(req); err != nil {
|
||||
r.zapLog.Warn("ShouldBindJSON error", zap.Error(err), middleware.GCtxRequestIDField(c))
|
||||
r.iResponse.ParamError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
out, err := r.iLogic.ListByIDs(c.Request.Context(), req)
|
||||
var ctx context.Context
|
||||
if r.wrapCtxFn != nil {
|
||||
ctx = r.wrapCtxFn(c)
|
||||
} else {
|
||||
ctx = c
|
||||
}
|
||||
|
||||
out, err := r.iLogic.ListByIDs(ctx, req)
|
||||
if err != nil {
|
||||
isIgnore := r.iResponse.Error(c, err)
|
||||
if !isIgnore {
|
||||
r.zapLog.Error("ListByIDs error", zap.Error(err), middleware.GCtxRequestIDField(c))
|
||||
}
|
||||
r.iResponse.Error(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -296,19 +335,24 @@ func (r *userExampleServiceRouter) ListByIDs_0(c *gin.Context) {
|
||||
|
||||
func (r *userExampleServiceRouter) List_0(c *gin.Context) {
|
||||
req := &ListUserExampleRequest{}
|
||||
var err error
|
||||
|
||||
if err := c.ShouldBindJSON(req); err != nil {
|
||||
if err = c.ShouldBindJSON(req); err != nil {
|
||||
r.zapLog.Warn("ShouldBindJSON error", zap.Error(err), middleware.GCtxRequestIDField(c))
|
||||
r.iResponse.ParamError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
out, err := r.iLogic.List(c.Request.Context(), req)
|
||||
var ctx context.Context
|
||||
if r.wrapCtxFn != nil {
|
||||
ctx = r.wrapCtxFn(c)
|
||||
} else {
|
||||
ctx = c
|
||||
}
|
||||
|
||||
out, err := r.iLogic.List(ctx, req)
|
||||
if err != nil {
|
||||
isIgnore := r.iResponse.Error(c, err)
|
||||
if !isIgnore {
|
||||
r.zapLog.Error("List error", zap.Error(err), middleware.GCtxRequestIDField(c))
|
||||
}
|
||||
r.iResponse.Error(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user