diff --git a/protoc-gen-go-crud/deliveries/template.go b/protoc-gen-go-crud/deliveries/template.go index bb6ee44..cd38c29 100644 --- a/protoc-gen-go-crud/deliveries/template.go +++ b/protoc-gen-go-crud/deliveries/template.go @@ -32,7 +32,7 @@ func ({{$firstLetter}} {{$svrType}}Service){{.OriginalName}}(c *gin.Context, in {{- end}} func ({{$firstLetter}} {{.ServiceType}}Service) Log(c *gin.Context) *zap.SugaredLogger { - return global.Logger(ctx).Named("{{.ServiceType}}Repo") + return global.Logger(c).Named("{{.ServiceType}}Repo") } ` diff --git a/protoc-gen-go-crud/deliveries/wire.go b/protoc-gen-go-crud/deliveries/wire.go index 2c1cd68..d3bddc8 100644 --- a/protoc-gen-go-crud/deliveries/wire.go +++ b/protoc-gen-go-crud/deliveries/wire.go @@ -2,6 +2,7 @@ package deliveries import ( "fmt" + "log" "os" "strings" "text/template" @@ -28,6 +29,12 @@ var ProviderSet = wire.NewSet({{ range $index, $element := .FunctionNames }}{{ i f := strings.Split(path, "V1") filename := fmt.Sprintf("./internal/%s/deliveries/wire.go", strings.ToLower(f[0])) + // 判断文件是否存在 + if _, err := os.Stat(strings.TrimPrefix(filename, "../")); err == nil { + log.Println("文件已存在,跳过生成:", filename) + return nil + } + functions := []string{} for _, set := range sets { functions = append(functions, fmt.Sprintf("New%sService", set)) diff --git a/protoc-gen-go-crud/internal/authorization/deliveries/authorization.go b/protoc-gen-go-crud/internal/authorization/deliveries/authorization.go index de6eae8..d8bdb4b 100644 --- a/protoc-gen-go-crud/internal/authorization/deliveries/authorization.go +++ b/protoc-gen-go-crud/internal/authorization/deliveries/authorization.go @@ -12,5 +12,5 @@ func (a AuthService) ListMenus(c *gin.Context, in *empty.Empty) (*authorizationV } func (a AuthService) Log(c *gin.Context) *zap.SugaredLogger { - return global.Logger(ctx).Named("AuthRepo") + return global.Logger(c).Named("AuthRepo") } diff --git a/protoc-gen-go-crud/internal/authorization/deliveries/role.go b/protoc-gen-go-crud/internal/authorization/deliveries/role.go index 12cc44d..4323af8 100644 --- a/protoc-gen-go-crud/internal/authorization/deliveries/role.go +++ b/protoc-gen-go-crud/internal/authorization/deliveries/role.go @@ -29,5 +29,5 @@ func (r RoleService) UpdateRole(c *gin.Context, in *authorizationV1.UpdateRoleRe } func (r RoleService) Log(c *gin.Context) *zap.SugaredLogger { - return global.Logger(ctx).Named("RoleRepo") + return global.Logger(c).Named("RoleRepo") } diff --git a/protoc-gen-go-crud/internal/users/deliveries/users.go b/protoc-gen-go-crud/internal/users/deliveries/users.go index 5184e3a..3b683c3 100644 --- a/protoc-gen-go-crud/internal/users/deliveries/users.go +++ b/protoc-gen-go-crud/internal/users/deliveries/users.go @@ -61,5 +61,5 @@ func (u UsersService) User(c *gin.Context, in *empty.Empty) (*components.User, e } func (u UsersService) Log(c *gin.Context) *zap.SugaredLogger { - return global.Logger(ctx).Named("UsersRepo") + return global.Logger(c).Named("UsersRepo") } diff --git a/protoc-gen-go-crud/protoc-gen-go-crud b/protoc-gen-go-crud/protoc-gen-go-crud index f1c8dbe..b781c48 100755 Binary files a/protoc-gen-go-crud/protoc-gen-go-crud and b/protoc-gen-go-crud/protoc-gen-go-crud differ diff --git a/protoc-gen-go-crud/repositories/wire.go b/protoc-gen-go-crud/repositories/wire.go index 9dcf552..82ce685 100644 --- a/protoc-gen-go-crud/repositories/wire.go +++ b/protoc-gen-go-crud/repositories/wire.go @@ -2,6 +2,7 @@ package repositories import ( "fmt" + "log" "os" "strings" "text/template" @@ -28,6 +29,11 @@ var ProviderSet = wire.NewSet({{ range $index, $element := .FunctionNames }}{{ i f := strings.Split(path, "V1") filename := fmt.Sprintf("./internal/%s/repositories/wire.go", strings.ToLower(f[0])) + // 判断文件是否存在 + if _, err := os.Stat(strings.TrimPrefix(filename, "../")); err == nil { + log.Println("文件已存在,跳过生成:", filename) + return nil + } functions := []string{} for _, set := range sets { functions = append(functions, fmt.Sprintf("New%sRepo", set)) diff --git a/protoc-gen-go-crud/usecase/wire.go b/protoc-gen-go-crud/usecase/wire.go index 958b09f..5e5bf5e 100644 --- a/protoc-gen-go-crud/usecase/wire.go +++ b/protoc-gen-go-crud/usecase/wire.go @@ -2,6 +2,7 @@ package usecase import ( "fmt" + "log" "os" "strings" "text/template" @@ -28,6 +29,12 @@ var ProviderSet = wire.NewSet({{ range $index, $element := .FunctionNames }}{{ i f := strings.Split(path, "V1") filename := fmt.Sprintf("./internal/%s/usecase/wire.go", strings.ToLower(f[0])) + // 判断文件是否存在 + if _, err := os.Stat(strings.TrimPrefix(filename, "../")); err == nil { + log.Println("文件已存在,跳过生成:", filename) + return nil + } + functions := []string{} for _, set := range sets { functions = append(functions, fmt.Sprintf("New%sUseCase", set))