diff --git a/protoc-gen-go-crud/api/v1/authorization/authorization.pb.go b/protoc-gen-go-crud/api/v1/authorization/authorization.pb.go index 3d0ca38..68fe3eb 100644 --- a/protoc-gen-go-crud/api/v1/authorization/authorization.pb.go +++ b/protoc-gen-go-crud/api/v1/authorization/authorization.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.30.0 -// protoc v3.21.12 +// protoc v4.23.3 // source: v1/authorization/authorization.proto package authorizationV1 diff --git a/protoc-gen-go-crud/api/v1/authorization/role.pb.go b/protoc-gen-go-crud/api/v1/authorization/role.pb.go index 6411d59..ccd7862 100644 --- a/protoc-gen-go-crud/api/v1/authorization/role.pb.go +++ b/protoc-gen-go-crud/api/v1/authorization/role.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.30.0 -// protoc v3.21.12 +// protoc v4.23.3 // source: v1/authorization/role.proto package authorizationV1 diff --git a/protoc-gen-go-crud/api/v1/components/dictionary.pb.go b/protoc-gen-go-crud/api/v1/components/dictionary.pb.go index c500468..9b54649 100644 --- a/protoc-gen-go-crud/api/v1/components/dictionary.pb.go +++ b/protoc-gen-go-crud/api/v1/components/dictionary.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.30.0 -// protoc v3.21.12 +// protoc v4.23.3 // source: v1/components/dictionary.proto package componentsV1 diff --git a/protoc-gen-go-crud/api/v1/components/enum.pb.go b/protoc-gen-go-crud/api/v1/components/enum.pb.go index 35daa5d..387f6ff 100644 --- a/protoc-gen-go-crud/api/v1/components/enum.pb.go +++ b/protoc-gen-go-crud/api/v1/components/enum.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.30.0 -// protoc v3.21.12 +// protoc v4.23.3 // source: v1/components/enum.proto package componentsV1 diff --git a/protoc-gen-go-crud/api/v1/components/schemas.pb.go b/protoc-gen-go-crud/api/v1/components/schemas.pb.go index ef537dc..c0292c7 100644 --- a/protoc-gen-go-crud/api/v1/components/schemas.pb.go +++ b/protoc-gen-go-crud/api/v1/components/schemas.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.30.0 -// protoc v3.21.12 +// protoc v4.23.3 // source: v1/components/schemas.proto package componentsV1 diff --git a/protoc-gen-go-crud/api/v1/users/users.pb.go b/protoc-gen-go-crud/api/v1/users/users.pb.go index 2374207..47231e9 100644 --- a/protoc-gen-go-crud/api/v1/users/users.pb.go +++ b/protoc-gen-go-crud/api/v1/users/users.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.30.0 -// protoc v3.21.12 +// protoc v4.23.3 // source: v1/users/users.proto package usersV1 diff --git a/protoc-gen-go-crud/deliveries/deliveries.go b/protoc-gen-go-crud/deliveries/deliveries.go index b9572b6..7ce3d1a 100644 --- a/protoc-gen-go-crud/deliveries/deliveries.go +++ b/protoc-gen-go-crud/deliveries/deliveries.go @@ -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 { diff --git a/protoc-gen-go-crud/deliveries/template.go b/protoc-gen-go-crud/deliveries/template.go index cd38c29..7906998 100644 --- a/protoc-gen-go-crud/deliveries/template.go +++ b/protoc-gen-go-crud/deliveries/template.go @@ -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}} @@ -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 { @@ -43,6 +55,7 @@ type serviceDesc struct { Metadata string // api/helloworld/helloworld.proto Methods []*methodDesc MethodSets map[string]*methodDesc + PackageName string } type methodDesc struct { diff --git a/protoc-gen-go-crud/internal/authorization/deliveries/authorization.go b/protoc-gen-go-crud/internal/authorization/deliveries/authorization.go index d8bdb4b..ee44277 100644 --- a/protoc-gen-go-crud/internal/authorization/deliveries/authorization.go +++ b/protoc-gen-go-crud/internal/authorization/deliveries/authorization.go @@ -5,6 +5,7 @@ import ( ) type AuthService struct { + ac usecase.IAuthUseCase } func (a AuthService) ListMenus(c *gin.Context, in *empty.Empty) (*authorizationV1.Menus, error) { @@ -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, + } +} diff --git a/protoc-gen-go-crud/internal/authorization/deliveries/role.go b/protoc-gen-go-crud/internal/authorization/deliveries/role.go index 4323af8..6c88f95 100644 --- a/protoc-gen-go-crud/internal/authorization/deliveries/role.go +++ b/protoc-gen-go-crud/internal/authorization/deliveries/role.go @@ -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) { @@ -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, + } +} diff --git a/protoc-gen-go-crud/internal/authorization/deliveries/wire.go b/protoc-gen-go-crud/internal/authorization/deliveries/wire.go deleted file mode 100644 index 3f90fca..0000000 --- a/protoc-gen-go-crud/internal/authorization/deliveries/wire.go +++ /dev/null @@ -1,5 +0,0 @@ -package deliveries - -import "github.com/google/wire" - -var ProviderSet = wire.NewSet(NewRoleService, NewAuthService) \ No newline at end of file diff --git a/protoc-gen-go-crud/internal/authorization/repositories/wire.go b/protoc-gen-go-crud/internal/authorization/repositories/wire.go deleted file mode 100644 index 7b2dc63..0000000 --- a/protoc-gen-go-crud/internal/authorization/repositories/wire.go +++ /dev/null @@ -1,5 +0,0 @@ -package repositories - -import "github.com/google/wire" - -var ProviderSet = wire.NewSet(NewRoleRepo, NewAuthRepo) \ No newline at end of file diff --git a/protoc-gen-go-crud/internal/authorization/usecase/wire.go b/protoc-gen-go-crud/internal/authorization/usecase/wire.go deleted file mode 100644 index 11e53df..0000000 --- a/protoc-gen-go-crud/internal/authorization/usecase/wire.go +++ /dev/null @@ -1,5 +0,0 @@ -package usecase - -import "github.com/google/wire" - -var ProviderSet = wire.NewSet(NewRoleUseCase, NewAuthUseCase) \ No newline at end of file diff --git a/protoc-gen-go-crud/internal/users/deliveries/users.go b/protoc-gen-go-crud/internal/users/deliveries/users.go index 7707507..88de667 100644 --- a/protoc-gen-go-crud/internal/users/deliveries/users.go +++ b/protoc-gen-go-crud/internal/users/deliveries/users.go @@ -6,6 +6,7 @@ import ( ) type UserService struct { + uc usecase.IUserUseCase } func (u UserService) ChangePassword(c *gin.Context, in *usersV1.ChangePasswordRequest) (*empty.Empty, error) { @@ -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, + } +} diff --git a/protoc-gen-go-crud/internal/users/deliveries/wire.go b/protoc-gen-go-crud/internal/users/deliveries/wire.go deleted file mode 100644 index 0c967e6..0000000 --- a/protoc-gen-go-crud/internal/users/deliveries/wire.go +++ /dev/null @@ -1,5 +0,0 @@ -package deliveries - -import "github.com/google/wire" - -var ProviderSet = wire.NewSet(NewUserService) \ No newline at end of file diff --git a/protoc-gen-go-crud/internal/users/repositories/wire.go b/protoc-gen-go-crud/internal/users/repositories/wire.go deleted file mode 100644 index 04b6c7d..0000000 --- a/protoc-gen-go-crud/internal/users/repositories/wire.go +++ /dev/null @@ -1,5 +0,0 @@ -package repositories - -import "github.com/google/wire" - -var ProviderSet = wire.NewSet(NewUserRepo) \ No newline at end of file diff --git a/protoc-gen-go-crud/internal/users/usecase/wire.go b/protoc-gen-go-crud/internal/users/usecase/wire.go deleted file mode 100644 index d4bb199..0000000 --- a/protoc-gen-go-crud/internal/users/usecase/wire.go +++ /dev/null @@ -1,5 +0,0 @@ -package usecase - -import "github.com/google/wire" - -var ProviderSet = wire.NewSet(NewUserUseCase) \ No newline at end of file diff --git a/protoc-gen-go-crud/protoc-gen-go-crud b/protoc-gen-go-crud/protoc-gen-go-crud index bbc10eb..5c2633f 100755 Binary files a/protoc-gen-go-crud/protoc-gen-go-crud and b/protoc-gen-go-crud/protoc-gen-go-crud differ