Files
sponge/api/serverNameExample/v1/userExample_router.pb.go
2023-05-26 00:47:20 +08:00

278 lines
8.0 KiB
Go

// Code generated by protoc-gen-go-gin. DO NOT EDIT.
package v1
import (
context "context"
gin "github.com/gin-gonic/gin"
errcode "github.com/zhufuyi/sponge/pkg/errcode"
middleware "github.com/zhufuyi/sponge/pkg/gin/middleware"
zap "go.uber.org/zap"
)
// import packages: context. errcode. middleware. zap. gin.
type UserExampleServiceLogicer interface {
Create(ctx context.Context, req *CreateUserExampleRequest) (*CreateUserExampleReply, error)
DeleteByID(ctx context.Context, req *DeleteUserExampleByIDRequest) (*DeleteUserExampleByIDReply, error)
GetByID(ctx context.Context, req *GetUserExampleByIDRequest) (*GetUserExampleByIDReply, error)
List(ctx context.Context, req *ListUserExampleRequest) (*ListUserExampleReply, error)
ListByIDs(ctx context.Context, req *ListUserExampleByIDsRequest) (*ListUserExampleByIDsReply, error)
UpdateByID(ctx context.Context, req *UpdateUserExampleByIDRequest) (*UpdateUserExampleByIDReply, error)
}
type UserExampleServiceOption func(*userExampleServiceOptions)
type userExampleServiceOptions struct {
isFromRPC bool
responser errcode.Responser
zapLog *zap.Logger
}
func (o *userExampleServiceOptions) apply(opts ...UserExampleServiceOption) {
for _, opt := range opts {
opt(o)
}
}
func WithUserExampleServiceHTTPResponse() UserExampleServiceOption {
return func(o *userExampleServiceOptions) {
o.isFromRPC = false
}
}
func WithUserExampleServiceRPCResponse() UserExampleServiceOption {
return func(o *userExampleServiceOptions) {
o.isFromRPC = true
}
}
func WithUserExampleServiceResponser(responser errcode.Responser) UserExampleServiceOption {
return func(o *userExampleServiceOptions) {
o.responser = responser
}
}
func WithUserExampleServiceLogger(zapLog *zap.Logger) UserExampleServiceOption {
return func(o *userExampleServiceOptions) {
o.zapLog = zapLog
}
}
func RegisterUserExampleServiceRouter(
iRouter gin.IRouter,
groupPathMiddlewares map[string][]gin.HandlerFunc,
singlePathMiddlewares map[string][]gin.HandlerFunc,
iLogic UserExampleServiceLogicer,
opts ...UserExampleServiceOption) {
o := &userExampleServiceOptions{}
o.apply(opts...)
if o.responser == nil {
o.responser = errcode.NewResponse(o.isFromRPC)
}
if o.zapLog == nil {
o.zapLog, _ = zap.NewProduction()
}
r := &userExampleServiceRouter{
iRouter: iRouter,
groupPathMiddlewares: groupPathMiddlewares,
singlePathMiddlewares: singlePathMiddlewares,
iLogic: iLogic,
iResponse: o.responser,
zapLog: o.zapLog,
}
r.register()
}
type userExampleServiceRouter struct {
iRouter gin.IRouter
groupPathMiddlewares map[string][]gin.HandlerFunc
singlePathMiddlewares map[string][]gin.HandlerFunc
iLogic UserExampleServiceLogicer
iResponse errcode.Responser
zapLog *zap.Logger
}
func (r *userExampleServiceRouter) register() {
r.iRouter.Handle("POST", "/api/v1/userExample", r.withMiddleware("/api/v1/userExample", r.Create_0)...)
r.iRouter.Handle("DELETE", "/api/v1/userExample/:id", r.withMiddleware("/api/v1/userExample/:id", r.DeleteByID_0)...)
r.iRouter.Handle("PUT", "/api/v1/userExample/:id", r.withMiddleware("/api/v1/userExample/:id", r.UpdateByID_0)...)
r.iRouter.Handle("GET", "/api/v1/userExample/:id", r.withMiddleware("/api/v1/userExample/:id", r.GetByID_0)...)
r.iRouter.Handle("POST", "/api/v1/userExample/list/ids", r.withMiddleware("/api/v1/userExample/list/ids", r.ListByIDs_0)...)
r.iRouter.Handle("POST", "/api/v1/userExample/list", r.withMiddleware("/api/v1/userExample/list", r.List_0)...)
}
func (r *userExampleServiceRouter) withMiddleware(path string, fn gin.HandlerFunc) []gin.HandlerFunc {
handlerFns := []gin.HandlerFunc{}
// determine if a route group is hit or miss, left prefix rule
for groupPath, fns := range r.groupPathMiddlewares {
if groupPath == "" || groupPath == "/" {
handlerFns = append(handlerFns, fns...)
continue
}
size := len(groupPath)
if len(path) < size {
continue
}
if groupPath == path[:size] {
handlerFns = append(handlerFns, fns...)
}
}
// determine if a single route has been hit
if fns, ok := r.singlePathMiddlewares[path]; ok {
handlerFns = append(handlerFns, fns...)
}
return append(handlerFns, fn)
}
func (r *userExampleServiceRouter) Create_0(c *gin.Context) {
req := &CreateUserExampleRequest{}
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)
if err != nil {
isIgnore := r.iResponse.Error(c, err)
if !isIgnore {
r.zapLog.Error("Create error", zap.Error(err), middleware.GCtxRequestIDField(c))
}
return
}
r.iResponse.Success(c, out)
}
func (r *userExampleServiceRouter) DeleteByID_0(c *gin.Context) {
req := &DeleteUserExampleByIDRequest{}
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 {
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)
if err != nil {
isIgnore := r.iResponse.Error(c, err)
if !isIgnore {
r.zapLog.Error("DeleteByID error", zap.Error(err), middleware.GCtxRequestIDField(c))
}
return
}
r.iResponse.Success(c, out)
}
func (r *userExampleServiceRouter) UpdateByID_0(c *gin.Context) {
req := &UpdateUserExampleByIDRequest{}
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 {
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)
if err != nil {
isIgnore := r.iResponse.Error(c, err)
if !isIgnore {
r.zapLog.Error("UpdateByID error", zap.Error(err), middleware.GCtxRequestIDField(c))
}
return
}
r.iResponse.Success(c, out)
}
func (r *userExampleServiceRouter) GetByID_0(c *gin.Context) {
req := &GetUserExampleByIDRequest{}
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 {
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)
if err != nil {
isIgnore := r.iResponse.Error(c, err)
if !isIgnore {
r.zapLog.Error("GetByID error", zap.Error(err), middleware.GCtxRequestIDField(c))
}
return
}
r.iResponse.Success(c, out)
}
func (r *userExampleServiceRouter) ListByIDs_0(c *gin.Context) {
req := &ListUserExampleByIDsRequest{}
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)
if err != nil {
isIgnore := r.iResponse.Error(c, err)
if !isIgnore {
r.zapLog.Error("ListByIDs error", zap.Error(err), middleware.GCtxRequestIDField(c))
}
return
}
r.iResponse.Success(c, out)
}
func (r *userExampleServiceRouter) List_0(c *gin.Context) {
req := &ListUserExampleRequest{}
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)
if err != nil {
isIgnore := r.iResponse.Error(c, err)
if !isIgnore {
r.zapLog.Error("List error", zap.Error(err), middleware.GCtxRequestIDField(c))
}
return
}
r.iResponse.Success(c, out)
}