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 1bd92b1 commit f9746f0
Show file tree
Hide file tree
Showing 21 changed files with 180 additions and 204 deletions.
211 changes: 105 additions & 106 deletions protoc-gen-go-crud/api/v1/users/users.pb.go

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions protoc-gen-go-crud/deliveries/deliveries.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ func GenerateDeliveriesFile(gen *protogen.Plugin, file *protogen.File, omitempty

filePrefix := strings.Split(file.GeneratedFilenamePrefix, "/")
filename := "../internal/" + filePrefix[1] + "/deliveries/" + filePrefix[2] + ".go"
dirname := "../internal/" + filePrefix[1]

// 判断文件是否存在
if _, err := os.Stat(strings.TrimPrefix(filename, "../")); err == nil {
log.Println("文件已存在,跳过生成:", filename)
if _, err := os.Stat(strings.TrimPrefix(dirname, "../")); err == nil {
log.Println("目录已存在,跳过生成:", dirname)
return nil
}

Expand Down
5 changes: 3 additions & 2 deletions protoc-gen-go-crud/deliveries/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ 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]))
dirname := fmt.Sprintf("./internal/%s", strings.ToLower(f[0]))

// 判断文件是否存在
if _, err := os.Stat(strings.TrimPrefix(filename, "../")); err == nil {
log.Println("文件已存在,跳过生成:", filename)
if _, err := os.Stat(strings.TrimPrefix(dirname, "../")); err == nil {
log.Println("目录已存在,跳过生成:", dirname)
return nil
}

Expand Down
5 changes: 3 additions & 2 deletions protoc-gen-go-crud/entities/entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ func GenerateEntitiesFile(gen *protogen.Plugin, file *protogen.File, omitempty b

filePrefix := strings.Split(file.GeneratedFilenamePrefix, "/")
filename := "../internal/" + filePrefix[1] + "/entities/" + filePrefix[2] + ".go"
dirname := "../internal/" + filePrefix[1]

// 判断文件是否存在
if _, err := os.Stat(strings.TrimPrefix(filename, "../")); err == nil {
log.Println("文件已存在,跳过生成:", filename)
if _, err := os.Stat(strings.TrimPrefix(dirname, "../")); err == nil {
log.Println("目录已存在,跳过生成:", dirname)
return nil
}

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

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package usecase

type IAuthUsecase interface {
type IAuthUseCase interface {
CreateAuth(ctx context.Context, in *authorizationV1.CreateAuthRequest) error
UpdateAuth(ctx context.Context, in *authorizationV1.UpdateAuthRequest) error
DeleteAuth(ctx context.Context, in *authorizationV1.DeleteAuthRequest) error
Expand All @@ -12,7 +12,7 @@ type IAuthUsecase interface {
type AuthUseCase struct {
}

func NewAuthUseCase() IAuthUsecase {
func NewAuthUseCase() IAuthUseCase {
return &AuthUseCase{}
}

Expand Down
4 changes: 2 additions & 2 deletions protoc-gen-go-crud/internal/authorization/usecase/role.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package usecase

type IRoleUsecase interface {
type IRoleUseCase interface {
CreateRole(ctx context.Context, in *authorizationV1.CreateRoleRequest) error
UpdateRole(ctx context.Context, in *authorizationV1.UpdateRoleRequest) error
DeleteRole(ctx context.Context, in *authorizationV1.DeleteRoleRequest) error
Expand All @@ -12,7 +12,7 @@ type IRoleUsecase interface {
type RoleUseCase struct {
}

func NewRoleUseCase() IRoleUsecase {
func NewRoleUseCase() IRoleUseCase {
return &RoleUseCase{}
}

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

This file was deleted.

32 changes: 16 additions & 16 deletions protoc-gen-go-crud/internal/users/deliveries/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,61 @@ import (
empty "github.com/golang/protobuf/ptypes/empty"
)

type UsersService struct {
type UserService struct {
}

func (u UsersService) ChangePassword(c *gin.Context, in *usersV1.ChangePasswordRequest) (*empty.Empty, error) {
func (u UserService) ChangePassword(c *gin.Context, in *usersV1.ChangePasswordRequest) (*empty.Empty, error) {
panic("todo")
}

func (u UsersService) CreateUser(c *gin.Context, in *usersV1.CreateUserRequest) (*empty.Empty, error) {
func (u UserService) CreateUser(c *gin.Context, in *usersV1.CreateUserRequest) (*empty.Empty, error) {
panic("todo")
}

func (u UsersService) DeleteUser(c *gin.Context, in *usersV1.DeleteUserRequest) (*empty.Empty, error) {
func (u UserService) DeleteUser(c *gin.Context, in *usersV1.DeleteUserRequest) (*empty.Empty, error) {
panic("todo")
}

func (u UsersService) EnableUser(c *gin.Context, in *usersV1.EnableUserRequest) (*empty.Empty, error) {
func (u UserService) EnableUser(c *gin.Context, in *usersV1.EnableUserRequest) (*empty.Empty, error) {
panic("todo")
}

func (u UsersService) GetUser(c *gin.Context, in *usersV1.GetUserRequest) (*components.User, error) {
func (u UserService) GetUser(c *gin.Context, in *usersV1.GetUserRequest) (*components.User, error) {
panic("todo")
}

func (u UsersService) ListUsers(c *gin.Context, in *usersV1.ListUsersRequest) (*usersV1.ListUsersReply, error) {
func (u UserService) ListUsers(c *gin.Context, in *usersV1.ListUsersRequest) (*usersV1.ListUsersReply, error) {
panic("todo")
}

func (u UsersService) Reset2FA(c *gin.Context, in *usersV1.Reset2FARequest) (*empty.Empty, error) {
func (u UserService) Reset2FA(c *gin.Context, in *usersV1.Reset2FARequest) (*empty.Empty, error) {
panic("todo")
}

func (u UsersService) ResetActivate(c *gin.Context, in *usersV1.ResetActivateRequest) (*empty.Empty, error) {
func (u UserService) ResetActivate(c *gin.Context, in *usersV1.ResetActivateRequest) (*empty.Empty, error) {
panic("todo")
}

func (u UsersService) ResetPassword(c *gin.Context, in *usersV1.ResetPasswordRequest) (*empty.Empty, error) {
func (u UserService) ResetPassword(c *gin.Context, in *usersV1.ResetPasswordRequest) (*empty.Empty, error) {
panic("todo")
}

func (u UsersService) UpdateCurrentUser(c *gin.Context, in *usersV1.UpdateCurrentUserRequest) (*empty.Empty, error) {
func (u UserService) UpdateCurrentUser(c *gin.Context, in *usersV1.UpdateCurrentUserRequest) (*empty.Empty, error) {
panic("todo")
}

func (u UsersService) UpdateUser(c *gin.Context, in *usersV1.UpdateUserRequest) (*empty.Empty, error) {
func (u UserService) UpdateUser(c *gin.Context, in *usersV1.UpdateUserRequest) (*empty.Empty, error) {
panic("todo")
}

func (u UsersService) UploadProfile(c *gin.Context, in *usersV1.UploadProfileRequest) (*usersV1.UploadProfileResponse, error) {
func (u UserService) UploadProfile(c *gin.Context, in *usersV1.UploadProfileRequest) (*usersV1.UploadProfileResponse, error) {
panic("todo")
}

func (u UsersService) User(c *gin.Context, in *empty.Empty) (*components.User, error) {
func (u UserService) User(c *gin.Context, in *empty.Empty) (*components.User, error) {
panic("todo")
}

func (u UsersService) Log(c *gin.Context) *zap.SugaredLogger {
return global.Logger(c).Named("UsersRepo")
func (u UserService) Log(c *gin.Context) *zap.SugaredLogger {
return global.Logger(c).Named("UserRepo")
}
5 changes: 0 additions & 5 deletions protoc-gen-go-crud/internal/users/deliveries/wire.go

This file was deleted.

4 changes: 2 additions & 2 deletions protoc-gen-go-crud/internal/users/entities/users.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package entities

type Users struct {
type User struct {
entity.BaseEntity
}

func (u *Users) TableName() string { return "userss" }
func (u *User) TableName() string { return "users" }
32 changes: 16 additions & 16 deletions protoc-gen-go-crud/internal/users/repositories/users.go
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
package repositories

type IUsersRepo interface {
CreateUsers(ctx context.Context, Users *entities.Users) error
UpdateUsers(ctx context.Context, updateFields []string, Users *entities.Users) error
GetUsers(ctx context.Context, id entity.ID) (*entities.Users, error)
GetUserss(ctx context.Context, filter *database.Filter) (res []*entities.User, count int64, err error)
DeleteUsers(ctx context.Context, id entity.ID) error
type IUserRepo interface {
CreateUser(ctx context.Context, User *entities.User) error
UpdateUser(ctx context.Context, updateFields []string, User *entities.User) error
GetUser(ctx context.Context, id entity.ID) (*entities.User, error)
GetUsers(ctx context.Context, filter *database.Filter) (res []*entities.User, count int64, err error)
DeleteUser(ctx context.Context, id entity.ID) error
Log(ctx context.Context) *zap.SugaredLogger
}

type UsersRepo struct {
type UserRepo struct {
}

func (u *UsersRepo) DB(ctx context.Context) *gorm.DB {
return global.DBFromContext(ctx).Model(&entities.Users{})
func (u *UserRepo) DB(ctx context.Context) *gorm.DB {
return global.DBFromContext(ctx).Model(&entities.User{})
}

func (u UsersRepo) CreateUsers(ctx context.Context, users *entities.Users) error {
func (u UserRepo) CreateUser(ctx context.Context, user *entities.User) error {
panic("todo")
}

func (u UsersRepo) UpdateUsers(ctx context.Context, updateFields []string, users *entities.Users) error {
func (u UserRepo) UpdateUser(ctx context.Context, updateFields []string, user *entities.User) error {
panic("todo")
}

func (u UsersRepo) GetUsers(ctx context.Context, id entity.ID) (*entities.Users, error) {
func (u UserRepo) GetUser(ctx context.Context, id entity.ID) (*entities.User, error) {
panic("todo")
}

func (u UsersRepo) DeleteUsers(ctx context.Context, id entity.ID) error {
func (u UserRepo) DeleteUser(ctx context.Context, id entity.ID) error {
panic("todo")
}

func (u UsersRepo) GetUserss(ctx context.Context, filter *database.Filter) (res []*entities.Users, count int64, err error) {
func (u UserRepo) GetUsers(ctx context.Context, filter *database.Filter) (res []*entities.User, count int64, err error) {
panic("todo")
}

func (u UsersRepo) Log(ctx context.Context) *zap.SugaredLogger {
return global.Logger(ctx).Named("UsersRepo")
func (u UserRepo) Log(ctx context.Context) *zap.SugaredLogger {
return global.Logger(ctx).Named("UserRepo")
}
5 changes: 0 additions & 5 deletions protoc-gen-go-crud/internal/users/repositories/wire.go

This file was deleted.

32 changes: 16 additions & 16 deletions protoc-gen-go-crud/internal/users/usecase/users.go
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
package usecase

type IUsersUsecase interface {
CreateUsers(ctx context.Context, in *usersV1.CreateUsersRequest) error
UpdateUsers(ctx context.Context, in *usersV1.UpdateUsersRequest) error
DeleteUsers(ctx context.Context, in *usersV1.DeleteUsersRequest) error
GetUsers(ctx context.Context, in *usersV1.GetUsersRequest) (*entities.Users, error)
ListUsers(ctx context.Context, in *usersV1.ListUsersRequest) ([]*entities.Users, int64, error)
type IUserUseCase interface {
CreateUser(ctx context.Context, in *usersV1.CreateUserRequest) error
UpdateUser(ctx context.Context, in *usersV1.UpdateUserRequest) error
DeleteUser(ctx context.Context, in *usersV1.DeleteUserRequest) error
GetUser(ctx context.Context, in *usersV1.GetUserRequest) (*entities.User, error)
ListUser(ctx context.Context, in *usersV1.ListUserRequest) ([]*entities.User, int64, error)
Log(ctx context.Context) *zap.SugaredLogger
}

type UsersUseCase struct {
type UserUseCase struct {
}

func NewUsersUseCase() IUsersUsecase {
return &UsersUseCase{}
func NewUserUseCase() IUserUseCase {
return &UserUseCase{}
}

func (u *UsersUseCase) CreateUsers(ctx context.Context, in *usersV1.CreateUsersRequest) error {
func (u *UserUseCase) CreateUser(ctx context.Context, in *usersV1.CreateUserRequest) error {
panic("todo")
}

func (u *UsersUseCase) UpdateUsers(ctx context.Context, in *usersV1.UpdateUsersRequest) error {
func (u *UserUseCase) UpdateUser(ctx context.Context, in *usersV1.UpdateUserRequest) error {
panic("todo")
}

func (u *UsersUseCase) DeleteUsers(ctx context.Context, in *usersV1.DeleteUsersRequest) error {
func (u *UserUseCase) DeleteUser(ctx context.Context, in *usersV1.DeleteUserRequest) error {
panic("todo")
}

func (u *UsersUseCase) GetUsers(ctx context.Context, in *usersV1.GetUsersRequest) (*entities.Users, error) {
func (u *UserUseCase) GetUser(ctx context.Context, in *usersV1.GetUserRequest) (*entities.User, error) {
panic("todo")
}

func (u *UsersUseCase) ListUsers(ctx context.Context, in *usersV1.ListUsersRequest) ([]*entities.Users, int64, error) {
func (u *UserUseCase) ListUser(ctx context.Context, in *usersV1.ListUserRequest) ([]*entities.User, int64, error) {
panic("todo")
}

func (u UsersUseCase) Log(ctx context.Context) *zap.SugaredLogger {
return global.Logger(ctx).Named("UsersRepo")
func (u UserUseCase) Log(ctx context.Context) *zap.SugaredLogger {
return global.Logger(ctx).Named("UserRepo")
}
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.
5 changes: 3 additions & 2 deletions protoc-gen-go-crud/repositories/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ func GenerateRespositoriesFile(gen *protogen.Plugin, file *protogen.File, omitem

filePrefix := strings.Split(file.GeneratedFilenamePrefix, "/")
filename := "../internal/" + filePrefix[1] + "/repositories/" + filePrefix[2] + ".go"
dirname := "../internal/" + filePrefix[1]

// 判断文件是否存在
if _, err := os.Stat(strings.TrimPrefix(filename, "../")); err == nil {
log.Println("文件已存在,跳过生成:", filename)
if _, err := os.Stat(strings.TrimPrefix(dirname, "../")); err == nil {
log.Println("目录已存在,跳过生成:", dirname)
return nil
}

Expand Down
5 changes: 3 additions & 2 deletions protoc-gen-go-crud/repositories/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,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]))
dirname := fmt.Sprintf("./internal/%s", strings.ToLower(f[0]))

// 判断文件是否存在
if _, err := os.Stat(strings.TrimPrefix(filename, "../")); err == nil {
log.Println("文件已存在,跳过生成:", filename)
if _, err := os.Stat(strings.TrimPrefix(dirname, "../")); err == nil {
log.Println("目录已存在,跳过生成:", dirname)
return nil
}
functions := []string{}
Expand Down
5 changes: 3 additions & 2 deletions protoc-gen-go-crud/usecase/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ func GenerateUseCasesFile(gen *protogen.Plugin, file *protogen.File, omitempty b

filePrefix := strings.Split(file.GeneratedFilenamePrefix, "/")
filename := "../internal/" + filePrefix[1] + "/usecase/" + filePrefix[2] + ".go"
dirname := "../internal/" + filePrefix[1]

// 判断文件是否存在
if _, err := os.Stat(strings.TrimPrefix(filename, "../")); err == nil {
log.Println("文件已存在,跳过生成:", filename)
if _, err := os.Stat(strings.TrimPrefix(dirname, "../")); err == nil {
log.Println("目录已存在,跳过生成:", dirname)
return nil
}

Expand Down
5 changes: 3 additions & 2 deletions protoc-gen-go-crud/usecase/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ 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]))
dirname := fmt.Sprintf("./internal/%s", strings.ToLower(f[0]))

// 判断文件是否存在
if _, err := os.Stat(strings.TrimPrefix(filename, "../")); err == nil {
log.Println("文件已存在,跳过生成:", filename)
if _, err := os.Stat(strings.TrimPrefix(dirname, "../")); err == nil {
log.Println("目录已存在,跳过生成:", dirname)
return nil
}

Expand Down

0 comments on commit f9746f0

Please sign in to comment.