mirror of
https://github.com/zhufuyi/sponge.git
synced 2025-10-05 16:57:07 +08:00
273 lines
7.4 KiB
Go
273 lines
7.4 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"
|
|
metadata "google.golang.org/grpc/metadata"
|
|
)
|
|
|
|
// import packages: context. errcode. middleware. zap. gin. metadata.
|
|
|
|
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, 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,
|
|
iLogic: iLogic,
|
|
iResponse: o.responser,
|
|
zapLog: o.zapLog,
|
|
}
|
|
r.register()
|
|
}
|
|
|
|
type userExampleServiceRouter struct {
|
|
iRouter gin.IRouter
|
|
iLogic UserExampleServiceLogicer
|
|
iResponse errcode.Responser
|
|
zapLog *zap.Logger
|
|
}
|
|
|
|
func (r *userExampleServiceRouter) register() {
|
|
r.iRouter.Handle("POST", "/api/v1/userExample", r.Create_0)
|
|
r.iRouter.Handle("DELETE", "/api/v1/userExample/:id", r.DeleteByID_0)
|
|
r.iRouter.Handle("PUT", "/api/v1/userExample/:id", r.UpdateByID_0)
|
|
r.iRouter.Handle("GET", "/api/v1/userExample/:id", r.GetByID_0)
|
|
r.iRouter.Handle("POST", "/api/v1/userExamples/ids", r.ListByIDs_0)
|
|
r.iRouter.Handle("POST", "/api/v1/userExamples", r.List_0)
|
|
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
md := metadata.New(nil)
|
|
for k, v := range c.Request.Header {
|
|
md.Set(k, v...)
|
|
}
|
|
newCtx := metadata.NewIncomingContext(c, md)
|
|
out, err := r.iLogic.Create(newCtx, 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
|
|
}
|
|
|
|
md := metadata.New(nil)
|
|
for k, v := range c.Request.Header {
|
|
md.Set(k, v...)
|
|
}
|
|
newCtx := metadata.NewIncomingContext(c, md)
|
|
out, err := r.iLogic.DeleteByID(newCtx, 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
|
|
}
|
|
|
|
md := metadata.New(nil)
|
|
for k, v := range c.Request.Header {
|
|
md.Set(k, v...)
|
|
}
|
|
newCtx := metadata.NewIncomingContext(c, md)
|
|
out, err := r.iLogic.UpdateByID(newCtx, 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
|
|
}
|
|
|
|
md := metadata.New(nil)
|
|
for k, v := range c.Request.Header {
|
|
md.Set(k, v...)
|
|
}
|
|
newCtx := metadata.NewIncomingContext(c, md)
|
|
out, err := r.iLogic.GetByID(newCtx, 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
|
|
}
|
|
|
|
md := metadata.New(nil)
|
|
for k, v := range c.Request.Header {
|
|
md.Set(k, v...)
|
|
}
|
|
newCtx := metadata.NewIncomingContext(c, md)
|
|
out, err := r.iLogic.ListByIDs(newCtx, 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
|
|
}
|
|
|
|
md := metadata.New(nil)
|
|
for k, v := range c.Request.Header {
|
|
md.Set(k, v...)
|
|
}
|
|
newCtx := metadata.NewIncomingContext(c, md)
|
|
out, err := r.iLogic.List(newCtx, 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)
|
|
}
|