Skip to content

Commit

Permalink
feat:优化
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxiaosu committed Jun 29, 2023
1 parent 4dc6a24 commit e5e68f2
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion protoc-gen-go-crud/deliveries/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
`
Expand Down
7 changes: 7 additions & 0 deletions protoc-gen-go-crud/deliveries/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package deliveries

import (
"fmt"
"log"
"os"
"strings"
"text/template"
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 1 addition & 1 deletion protoc-gen-go-crud/internal/users/deliveries/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Binary file modified protoc-gen-go-crud/protoc-gen-go-crud
Binary file not shown.
6 changes: 6 additions & 0 deletions protoc-gen-go-crud/repositories/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package repositories

import (
"fmt"
"log"
"os"
"strings"
"text/template"
Expand All @@ -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))
Expand Down
7 changes: 7 additions & 0 deletions protoc-gen-go-crud/usecase/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package usecase

import (
"fmt"
"log"
"os"
"strings"
"text/template"
Expand All @@ -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))
Expand Down

0 comments on commit e5e68f2

Please sign in to comment.