Skip to content

Commit

Permalink
优化delivery
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxiaosu committed Jul 4, 2023
1 parent 97a16c8 commit db234db
Show file tree
Hide file tree
Showing 18 changed files with 48 additions and 40 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion protoc-gen-go-crud/api/v1/authorization/role.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion protoc-gen-go-crud/api/v1/components/dictionary.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion protoc-gen-go-crud/api/v1/components/enum.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion protoc-gen-go-crud/api/v1/components/schemas.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion protoc-gen-go-crud/api/v1/users/users.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions protoc-gen-go-crud/deliveries/deliveries.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func genService(_ *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFi
ServiceType: service.GoName,
ServiceName: string(service.Desc.FullName()),
Metadata: file.Desc.Path(),
PackageName: string(file.GoPackageName),
}

for _, method := range service.Methods {
Expand Down
21 changes: 17 additions & 4 deletions protoc-gen-go-crud/deliveries/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ import (
)

var crudTemplate = `
type {{.ServiceType}}Service struct {
}
{{$firstLetter := (GetFirstLetter .ServiceType)}}
{{$packageName := .PackageName}}
{{$svrType := .ServiceType}}
{{$svrName := .ServiceName}}
type {{.ServiceType}}Service struct {
{{$firstLetter}}c usecase.I{{.ServiceType}}UseCase
}
{{- range .MethodSets}}
{{$request := .Request}}
{{$reply := .Reply}}
{{- if not (IsHasPackagePrefix .Request)}}
{{$request = printf "%s.%s" .PackageName .Request}}
{{- end}}
Expand All @@ -35,6 +38,15 @@ func ({{$firstLetter}} {{.ServiceType}}Service) Log(c *gin.Context) *zap.Sugared
return global.Logger(c).Named("{{.ServiceType}}Repo")
}
func New{{.ServiceType}}Service({{$firstLetter}}c usecase.I{{$svrType}}UseCase) {{$packageName}}.{{.ServiceType}}HTTPServer{
return &{{.ServiceType}}Service{
{{$firstLetter}}c: {{$firstLetter}}c,
}
}
`

type serviceDesc struct {
Expand All @@ -43,6 +55,7 @@ type serviceDesc struct {
Metadata string // api/helloworld/helloworld.proto
Methods []*methodDesc
MethodSets map[string]*methodDesc
PackageName string
}

type methodDesc struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
)

type AuthService struct {
ac usecase.IAuthUseCase
}

func (a AuthService) ListMenus(c *gin.Context, in *empty.Empty) (*authorizationV1.Menus, error) {
Expand All @@ -14,3 +15,9 @@ func (a AuthService) ListMenus(c *gin.Context, in *empty.Empty) (*authorizationV
func (a AuthService) Log(c *gin.Context) *zap.SugaredLogger {
return global.Logger(c).Named("AuthRepo")
}

func NewAuthService(ac usecase.IAuthUseCase) authorizationV1.AuthHTTPServer {
return &AuthService{
ac: ac,
}
}
10 changes: 10 additions & 0 deletions protoc-gen-go-crud/internal/authorization/deliveries/role.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package deliveries

import (
authorizationV1 "github.com/fynntang/protobuf-gen-go/protoc-gen-go-crud/api/v1/authorization"
components "github.com/fynntang/protobuf-gen-go/protoc-gen-go-crud/api/v1/components"
"github.com/fynntang/protobuf-gen-go/protoc-gen-go-crud/internal/authorization/usecase"
"github.com/gin-gonic/gin"
empty "github.com/golang/protobuf/ptypes/empty"
)

type RoleService struct {
rc usecase.IRoleUseCase
}

func (r RoleService) CreateRole(c *gin.Context, in *authorizationV1.CreateRoleRequest) (*empty.Empty, error) {
Expand All @@ -31,3 +35,9 @@ func (r RoleService) UpdateRole(c *gin.Context, in *authorizationV1.UpdateRoleRe
func (r RoleService) Log(c *gin.Context) *zap.SugaredLogger {
return global.Logger(c).Named("RoleRepo")
}

func NewRoleService(rc usecase.IRoleUseCase) authorizationV1.RoleHTTPServer {
return &RoleService{
rc: rc,
}
}
5 changes: 0 additions & 5 deletions protoc-gen-go-crud/internal/authorization/deliveries/wire.go

This file was deleted.

This file was deleted.

5 changes: 0 additions & 5 deletions protoc-gen-go-crud/internal/authorization/usecase/wire.go

This file was deleted.

7 changes: 7 additions & 0 deletions protoc-gen-go-crud/internal/users/deliveries/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
)

type UserService struct {
uc usecase.IUserUseCase
}

func (u UserService) ChangePassword(c *gin.Context, in *usersV1.ChangePasswordRequest) (*empty.Empty, error) {
Expand Down Expand Up @@ -63,3 +64,9 @@ func (u UserService) User(c *gin.Context, in *empty.Empty) (*components.User, er
func (u UserService) Log(c *gin.Context) *zap.SugaredLogger {
return global.Logger(c).Named("UserRepo")
}

func NewUserService(uc usecase.IUserUseCase) usersV1.UserHTTPServer {
return &UserService{
uc: uc,
}
}
5 changes: 0 additions & 5 deletions protoc-gen-go-crud/internal/users/deliveries/wire.go

This file was deleted.

5 changes: 0 additions & 5 deletions protoc-gen-go-crud/internal/users/repositories/wire.go

This file was deleted.

5 changes: 0 additions & 5 deletions protoc-gen-go-crud/internal/users/usecase/wire.go

This file was deleted.

Binary file modified protoc-gen-go-crud/protoc-gen-go-crud
Binary file not shown.

0 comments on commit db234db

Please sign in to comment.