diff --git a/.gitignore b/.gitignore index 3095296..7dabf16 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,5 @@ /bin/ready/pkg/model/ /bin/ready/ /bin/sync_service/ +/bin/sync_service_test/ +/bin/crud_service/ diff --git a/Makefile b/Makefile index dcd550d..c50cf24 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ SERVICENAME=crud_generator SERVICEURL=github.com/ManyakRus/$(SERVICENAME) -FILEMAIN=./internal/main.go +FILEMAIN=./cmd/$(SERVICENAME)/main.go FILEAPP=./bin/$(SERVICENAME) NEW_REPO=$(SERVICENAME) @@ -11,7 +11,7 @@ run: clear go build -race -o $(FILEAPP) $(FILEMAIN) # cd ./bin && \ - ./bin/app_race + ./bin/$(SERVICENAME) mod: clear go get -u ./... @@ -21,7 +21,7 @@ mod: build: clear go build -race -o $(FILEAPP) $(FILEMAIN) - cd ./cmd && \ + cd ./scripts && \ ./VersionToFile.py lint: diff --git a/bin/crud_generator b/bin/crud_generator new file mode 100755 index 0000000..843b9e5 Binary files /dev/null and b/bin/crud_generator differ diff --git a/bin/date.txt b/bin/date.txt index 8f44411..99a18f2 100644 --- a/bin/date.txt +++ b/bin/date.txt @@ -1 +1 @@ -2023-09-11 13:17:12.998 \ No newline at end of file +2023-11-15 12:11:15.838 \ No newline at end of file diff --git a/bin/subversion.txt b/bin/subversion.txt index a9c7f8d..4424fb1 100644 --- a/bin/subversion.txt +++ b/bin/subversion.txt @@ -1 +1 @@ -00130 \ No newline at end of file +00133 \ No newline at end of file diff --git a/bin/templates/.gitignore b/bin/templates/.gitignore new file mode 100644 index 0000000..c270948 --- /dev/null +++ b/bin/templates/.gitignore @@ -0,0 +1,7 @@ +.env +/bin/.env + +/.idea/ +.vscode +/log.txt +cover.out diff --git a/bin/templates/Makefile_ b/bin/templates/Makefile_ new file mode 100644 index 0000000..455fcb8 --- /dev/null +++ b/bin/templates/Makefile_ @@ -0,0 +1,55 @@ +SERVICENAME=sync_service +SERVICEURL=github.com/ManyakRus/$(SERVICENAME) + +FILEMAIN=./cmd/$(SERVICENAME)/main.go +FILEAPP=./bin/$(SERVICENAME) + +NEW_REPO=$(SERVICENAME) + + +run: + clear + go build -race -o $(FILEAPP) $(FILEMAIN) + # cd ./bin && \ + ./bin/$(SERVICENAME) +mod: + clear + go get -u ./... + go mod tidy -compat=1.18 + go mod vendor + go fmt ./... +build: + clear + go build -race -o $(FILEAPP) $(FILEMAIN) + cd ./scripts && \ + ./VersionToFile.py + +lint: + clear + go fmt ./... + golangci-lint run ./internal/... + golangci-lint run ./pkg/... + gocyclo -over 10 ./internal + gocyclo -over 10 ./pkg + gocritic check ./internal/... + gocritic check ./pkg/... + staticcheck ./internal/... + staticcheck ./pkg/... +run.test: + clear + go fmt ./... + go test -coverprofile cover.out ./internal/v0/app/... + go tool cover -func=cover.out +newrepo: + sed -i 's+$(SERVICEURL)+$(NEW_REPO)+g' go.mod + find -name *.go -not -path "*/vendor/*"|xargs sed -i 's+$(SERVICEURL)+$(NEW_REPO)+g' +graph: + clear + image_packages ./ docs/packages.graphml +conn: + clear + image_connections ./internal docs/connections.graphml $(SERVICENAME) +init: + clear + go mod init gitlab.aescorp.ru/dsp_dev/claim/sync_service + go mod tidy \ No newline at end of file diff --git a/bin/templates/pkg/network/grpc/generation_code.sh b/bin/templates/api/generation_code.sh_ similarity index 86% rename from bin/templates/pkg/network/grpc/generation_code.sh rename to bin/templates/api/generation_code.sh_ index 800f088..7c46f85 100755 --- a/bin/templates/pkg/network/grpc/generation_code.sh +++ b/bin/templates/api/generation_code.sh_ @@ -3,4 +3,4 @@ ADAPT_PATH=./ clear -protoc --go_out=${ADAPT_PATH} --nrpc_out=./ --go_opt=paths=import --go-grpc_out=${ADAPT_PATH} --go-grpc_opt=paths=import ${ADAPT_PATH}Sync_service.proto +protoc --go_out=${ADAPT_PATH} --nrpc_out=./ --go_opt=paths=import --go-grpc_out=${ADAPT_PATH} --go-grpc_opt=paths=import ${ADAPT_PATH}sync_service.proto diff --git a/bin/templates/pkg/network/grpc/service.proto b/bin/templates/api/service.proto_ similarity index 100% rename from bin/templates/pkg/network/grpc/service.proto rename to bin/templates/api/service.proto_ diff --git a/bin/templates/bin/date.txt b/bin/templates/bin/date.txt new file mode 100644 index 0000000..99a18f2 --- /dev/null +++ b/bin/templates/bin/date.txt @@ -0,0 +1 @@ +2023-11-15 12:11:15.838 \ No newline at end of file diff --git a/bin/templates/bin/settings.txt b/bin/templates/bin/settings.txt new file mode 100644 index 0000000..01ca9cb --- /dev/null +++ b/bin/templates/bin/settings.txt @@ -0,0 +1,29 @@ +STAGE="local" +LOG_LEVEL="debug" + +#---------------------Database settings--------------------- +#DB_HOST - Database server name or ip-address. Only Postgres SQL +DB_HOST="" + +#DB_NAME - Database table name +DB_NAME="" + +#DB_SCHEME - Database schema name +DB_SCHEME="public" + +#DB_PORT - Database port number +DB_PORT="5432" + +#DB_USER - Database login (user) +DB_USER="" + +#DB_PASSWORD - Database login password +DB_PASSWORD="" + + +#---------------------NATS messages broker settings--------------------- +NATS_HOST="" +NATS_PORT="" +NATS_LOGIN="" +NATS_PASSWORD="" + diff --git a/bin/templates/bin/subversion.txt b/bin/templates/bin/subversion.txt new file mode 100644 index 0000000..4424fb1 --- /dev/null +++ b/bin/templates/bin/subversion.txt @@ -0,0 +1 @@ +00133 \ No newline at end of file diff --git a/cmd/test_copy/version.txt b/bin/templates/bin/version.txt similarity index 100% rename from cmd/test_copy/version.txt rename to bin/templates/bin/version.txt diff --git a/bin/templates/pkg/db/constants/constants.go b/bin/templates/pkg/db/constants/constants.go new file mode 100644 index 0000000..d8a63a6 --- /dev/null +++ b/bin/templates/pkg/db/constants/constants.go @@ -0,0 +1,7 @@ +package constants + +const CONNECTION_ID_TEST = 3 + +const TIMEOUT_DB_SECONDS = 30 + +const TEXT_RECORD_NOT_FOUND = "record not found" diff --git a/bin/templates/pkg/network/grpc/service_client.go_ b/bin/templates/pkg/network/grpc/service_client.go_ new file mode 100644 index 0000000..ecb859e --- /dev/null +++ b/bin/templates/pkg/network/grpc/service_client.go_ @@ -0,0 +1,106 @@ +package grpc_client + +import ( + "github.com/ManyakRus/starter/contextmain" + "github.com/ManyakRus/starter/log" + "github.com/ManyakRus/starter/stopapp" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/constants" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_proto" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" + "os" + "strings" +) + +type SettingsINI struct { + SYNC_SERVICE_HOST string + SYNC_SERVICE_PORT string +} + +var Settings SettingsINI + +var Conn *grpc.ClientConn +var Client grpc_proto.SyncServiceClient + +func Connect() { + var err error + + if Settings.SYNC_SERVICE_HOST == "" { + FillSettings() + } + + addr := Settings.SYNC_SERVICE_HOST + ":" + Settings.SYNC_SERVICE_PORT + Conn, err = grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials())) + if err != nil { + log.Fatalf("did not connect: %v", err) + } + + log.Info("GRPC client connected. Address: ", addr) + + Client = grpc_proto.NewSyncServiceClient(Conn) +} + +func FillSettings() { + Settings = SettingsINI{} + Settings.SYNC_SERVICE_HOST = os.Getenv("SYNC_SERVICE_HOST") + Settings.SYNC_SERVICE_PORT = os.Getenv("SYNC_SERVICE_PORT") + + if Settings.SYNC_SERVICE_HOST == "" { + log.Panic("Need fill SYNC_SERVICE_HOST ! in OS Environment ") + } + + if Settings.SYNC_SERVICE_PORT == "" { + log.Panic("Need fill SYNC_SERVICE_PORT ! in OS Environment ") + } +} + +// WaitStop - ожидает отмену глобального контекста +func WaitStop() { + + select { + case <-contextmain.GetContext().Done(): + log.Warn("Context app is canceled. grpc_connect") + } + + // ждём пока отправляемых сейчас сообщений будет =0 + stopapp.WaitTotalMessagesSendingNow("sync_service_client") + + // закрываем соединение + CloseConnection() + stopapp.GetWaitGroup_Main().Done() +} + +// Start - необходимые процедуры для запуска сервера GRPC +func Start() { + Connect() + + stopapp.GetWaitGroup_Main().Add(1) + go WaitStop() + +} + +func CloseConnection() { + err := Conn.Close() + if err != nil { + log.Panic("GRPC client CloseConnection() error: ", err) + } else { + log.Info("GRPC client connection closed") + } +} + +// IsRecordNotFound - возвращает true если ошибка = "record not found" +func IsRecordNotFound(err error) bool { + Otvet := false + + if err == nil { + return Otvet + } + + TextErr := err.Error() + pos1 := strings.Index(TextErr, constants.TEXT_RECORD_NOT_FOUND) + if pos1 >= 0 { + Otvet = true + } + + return Otvet +} diff --git a/bin/templates/pkg/network/grpc/service_client_test.go_ b/bin/templates/pkg/network/grpc/service_client_test.go_ new file mode 100644 index 0000000..cf46fa7 --- /dev/null +++ b/bin/templates/pkg/network/grpc/service_client_test.go_ @@ -0,0 +1,23 @@ +package grpc_client + +import ( + "errors" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/constants" + "testing" +) + +func TestIsRecordNotFound(t *testing.T) { + + err := errors.New(constants.TEXT_RECORD_NOT_FOUND + " !") + Otvet := IsRecordNotFound(err) + if Otvet != true { + t.Error("TestIsRecordNotFound() error: false") + } + + err = errors.New("rpc error: code = Unknown desc = record not found") + Otvet = IsRecordNotFound(err) + if Otvet != true { + t.Error("TestIsRecordNotFound() error: false") + } + +} diff --git a/bin/templates/pkg/network/nrpc/nrpc_client/nrpc_client.go_ b/bin/templates/pkg/network/nrpc/nrpc_client/nrpc_client.go_ index 77ef4de..cbdc28a 100644 --- a/bin/templates/pkg/network/nrpc/nrpc_client/nrpc_client.go_ +++ b/bin/templates/pkg/network/nrpc/nrpc_client/nrpc_client.go_ @@ -4,7 +4,7 @@ import ( "encoding/json" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_proto" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/nrpc/nrpc_client" - "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/nrpc/nrpc_client/constants" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/nrpc/grpc_client/constants" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types" "log" ) diff --git a/bin/templates/pkg/object_model/types/alias/alias.go b/bin/templates/pkg/object_model/types/alias/alias.go new file mode 100644 index 0000000..4007f5d --- /dev/null +++ b/bin/templates/pkg/object_model/types/alias/alias.go @@ -0,0 +1,35 @@ +// Package alias -- специальные типы РАПИРы +package alias + +// PaymentId -- ID платёжки +type PaymentId int64 + +// InvoiceId -- ID счёт-фактуры +type InvoiceId int64 + +// LawsuitId -- ID претензии +type LawsuitId int64 + +// LawsuitNumber -- номер претензии +type LawsuitNumber string + +// ClaimNumber -- Номер дела +type ClaimNumber string + +// TrialNumber -- Номер иска +type TrialNumber string + +// ContractNumber -- Номер договора +type ContractNumber string + +// FrontDate -- специальный тип даты для фронта +type FrontDate string + +// FrontTime -- специальный тип даты-времени для фронта +type FrontTime string + +// PaymentRegisteredAt -- тип даты времени при регистрации в системе +type PaymentRegisteredAt string + +// IsAfterNotify -- признак регистрации документа после уведомления +type IsAfterNotify bool diff --git a/cmd/VersionToFile.py b/bin/templates/scripts/VersionToFile.py similarity index 100% rename from cmd/VersionToFile.py rename to bin/templates/scripts/VersionToFile.py diff --git a/cmd/main.go b/cmd/crud_generator/main.go similarity index 100% rename from cmd/main.go rename to cmd/crud_generator/main.go diff --git a/cmd/main_test.go b/cmd/crud_generator/main_test.go similarity index 100% rename from cmd/main_test.go rename to cmd/crud_generator/main_test.go diff --git a/internal/config/config.go b/internal/config/config.go index 1f7688b..9f9f5df 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -16,6 +16,7 @@ type SettingsINI struct { TEMPLATE_FOLDERNAME string TEMPLATE_FOLDERNAME_MODEL string TEMPLATE_FOLDERNAME_DB string + TEMPLATE_FOLDERNAME_GRPC string TEMPLATE_FOLDERNAME_GRPC_PROTO string TEMPLATE_FOLDERNAME_GRPC_SERVER string TEMPLATE_FOLDERNAME_GRPC_CLIENT string @@ -138,6 +139,7 @@ func FillSettings() { Settings.TEMPLATE_FOLDERNAME_MAIN = os.Getenv("TEMPLATE_FOLDERNAME_MAIN") Settings.TEMPLATE_REPOSITORY_URL = os.Getenv("TEMPLATE_REPOSITORY_URL") + Settings.TEMPLATE_FOLDERNAME_GRPC = os.Getenv("TEMPLATE_FOLDERNAME_GRPC") } diff --git a/internal/create_files/create_files.go b/internal/create_files/create_files.go index e457e62..c63cfef 100644 --- a/internal/create_files/create_files.go +++ b/internal/create_files/create_files.go @@ -270,6 +270,24 @@ func FindGRPCServerlURL() string { return Otvet } +// FindGRPCClientURL - возвращает URL репозитория с пакетом "client_grpc" +func FindGRPClientURL() string { + Otvet := "" + + Otvet = config.Settings.SERVICE_REPOSITORY_URL + "/" + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + + return Otvet +} + +// FindGRPCConstantsURL - возвращает URL репозитория с пакетом "client_grpc" +func FindGRPCConstantsURL() string { + Otvet := "" + + Otvet = config.Settings.SERVICE_REPOSITORY_URL + "/" + config.Settings.TEMPLATE_FOLDERNAME_GRPC + "/" + "constants" + + return Otvet +} + // FindNRPCServerlURL - возвращает URL репозитория с пакетом "server_nrpc" func FindNRPCServerlURL() string { Otvet := "" @@ -279,7 +297,7 @@ func FindNRPCServerlURL() string { return Otvet } -// FindProtoURL - возвращает URL репозитория с пакетом "proto" +// FindProtoURL - возвращает URL репозитория с файлом .proto func FindProtoURL() string { Otvet := "" @@ -288,6 +306,24 @@ func FindProtoURL() string { return Otvet } +// FindGRPCProtoURL - возвращает URL репозитория с пакетом "grpc_proto" +func FindGRPCProtoURL() string { + Otvet := "" + + Otvet = config.Settings.SERVICE_REPOSITORY_URL + "/" + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + "/" + "grpc_proto" + + return Otvet +} + +// FindModelTableURL - возвращает URL репозитория model для таблицы TableName +func FindModelTableURL(TableName string) string { + Otvet := "" + + Otvet = config.Settings.SERVICE_REPOSITORY_URL + "/" + config.Settings.TEMPLATE_FOLDERNAME_MODEL + "/" + TableName + + return Otvet +} + func FindTextDefaultValue(Type_go string) string { var Otvet string @@ -428,3 +464,33 @@ func DeleteTemplateRepositoryImports(Text string) string { return Otvet } + +// ReplaceServiceURLImports - заменяет URL репозитория шаблона на URL репозитория сервиса +func ReplaceServiceURLImports(Text string) string { + Otvet := Text + + if config.Settings.SERVICE_REPOSITORY_URL == "" { + return Otvet + } + + if config.Settings.TEMPLATE_REPOSITORY_URL == "" { + return Otvet + } + + if config.Settings.USE_DEFAULT_TEMPLATE == false { + return Otvet + } + + // + TextFind := "import (" + pos1 := strings.Index(Otvet, TextFind) + if pos1 < 0 { + return Otvet + } + + TEMPLATE_REPOSITORY_URL := config.Settings.TEMPLATE_REPOSITORY_URL + SERVICE_REPOSITORY_URL := config.Settings.SERVICE_REPOSITORY_URL + Otvet = strings.ReplaceAll(Otvet, TEMPLATE_REPOSITORY_URL, SERVICE_REPOSITORY_URL) + + return Otvet +} diff --git a/internal/create_files/crud_starter/crud_starter.go b/internal/create_files/crud_starter/crud_starter.go index b04d7ef..a874c15 100644 --- a/internal/create_files/crud_starter/crud_starter.go +++ b/internal/create_files/crud_starter/crud_starter.go @@ -68,6 +68,9 @@ func CreateFileCrudStarter(MapAll map[string]*types.Table) error { TextCrudStarter = TextCrudStarter + "\n" + TextNRPC } + //замена импортов на новые URL + TextCrudStarter = create_files.ReplaceServiceURLImports(TextCrudStarter) + //запись файла err = os.WriteFile(FilenameReadyCrudStarter, []byte(TextCrudStarter), constants.FILE_PERMISSIONS) @@ -137,7 +140,7 @@ func FindTextImportDB1(Table1 *types.Table) string { // FindTextImportGRPC1 - возвращает текст импорта GRPC для 1 таблицы func FindTextImportGRPC1(Table1 *types.Table) string { - GRPC_URL := config.Settings.SERVICE_REPOSITORY_URL + "/" + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + GRPC_URL := config.Settings.SERVICE_REPOSITORY_URL TableName := strings.ToLower(Table1.Name) Otvet := "\n\t\"" + GRPC_URL + "/" + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + "/grpc_" + TableName + `"` diff --git a/internal/create_files/db/db.go b/internal/create_files/db/db.go index 2ffc10c..b79804f 100644 --- a/internal/create_files/db/db.go +++ b/internal/create_files/db/db.go @@ -95,6 +95,9 @@ func CreateFiles(Table1 *types.Table) error { TextDB = ReplaceText_is_deleted_deleted_at(TextDB, Table1) TextDB = create_files.DeleteImportModel(TextDB) + //замена импортов на новые URL + TextDB = create_files.ReplaceServiceURLImports(TextDB) + //запись файла err = os.WriteFile(FilenameReadyDB, []byte(TextDB), constants.FILE_PERMISSIONS) @@ -157,6 +160,9 @@ func CreateTestFiles(Table1 *types.Table) error { // замена ID на PrimaryKey TextDB = create_files.ReplacePrimaryKeyID(TextDB, Table1) + //замена импортов на новые URL + TextDB = create_files.ReplaceServiceURLImports(TextDB) + //запись файла err = os.WriteFile(FilenameReadyDB, []byte(TextDB), constants.FILE_PERMISSIONS) diff --git a/internal/create_files/generation_code_sh/generation_code_sh.go b/internal/create_files/generation_code_sh/generation_code_sh.go new file mode 100644 index 0000000..585534a --- /dev/null +++ b/internal/create_files/generation_code_sh/generation_code_sh.go @@ -0,0 +1,66 @@ +package generation_code_sh + +import ( + "github.com/ManyakRus/crud_generator/internal/config" + "github.com/ManyakRus/crud_generator/internal/folders" + "github.com/ManyakRus/starter/log" + "github.com/ManyakRus/starter/micro" + "os" + "strings" +) + +// CreateAllFiles - создаёт все файлы в папке grpc proto +func CreateAllFiles() error { + var err error + + if config.Settings.USE_DEFAULT_TEMPLATE == false { + return err + } + + if config.Settings.NEED_CREATE_GRPC == false { + return err + } + + err = CreateFileGenerationCodeSh() + if err != nil { + log.Error("CreateFileGenerationCodeSh() error: ", err) + return err + } + + return err +} + +// CreateFileGenerationCodeSh - создаёт 1 файл в папке grpc proto +func CreateFileGenerationCodeSh() error { + var err error + + if config.Settings.USE_DEFAULT_TEMPLATE == false { + return err + } + + //чтение файлов + DirBin := micro.ProgramDir_bin() + DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile() + DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile() + DirTemplatesProto := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + micro.SeparatorFile() + DirReadyProto := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + micro.SeparatorFile() + FilenameReadyProto := DirReadyProto + "generation_code.sh" + FilenameTemplateProto := DirTemplatesProto + "generation_code.sh_" + + bytes, err := os.ReadFile(FilenameTemplateProto) + if err != nil { + log.Panic("ReadFile() ", FilenameTemplateProto, " error: ", err) + } + TextGenerationCode := string(bytes) + + //создадим папку ready proto + folders.CreateFolder(DirReadyProto) + + //replace + TextGenerationCode = strings.ReplaceAll(TextGenerationCode, config.Settings.TEMPLATE_SERVICE_NAME, config.Settings.SERVICE_NAME) + + //запись файла + err = os.WriteFile(FilenameReadyProto, []byte(TextGenerationCode), 0777) + + return err +} diff --git a/internal/create_files/generation_code_sh/generation_code_sh_test.go b/internal/create_files/generation_code_sh/generation_code_sh_test.go new file mode 100644 index 0000000..0bce4cc --- /dev/null +++ b/internal/create_files/generation_code_sh/generation_code_sh_test.go @@ -0,0 +1 @@ +package generation_code_sh diff --git a/internal/create_files/grpc_client/grpc_client.go b/internal/create_files/grpc_client/grpc_client.go index 9eb6ccf..71b7d57 100644 --- a/internal/create_files/grpc_client/grpc_client.go +++ b/internal/create_files/grpc_client/grpc_client.go @@ -51,8 +51,8 @@ func CreateFiles(Table1 *types.Table) error { DirBin := micro.ProgramDir_bin() DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile() DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile() - DirTemplatesGRPCClient := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile() - DirReadyGRPCClient := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile() + DirTemplatesGRPCClient := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile() + DirReadyGRPCClient := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile() FilenameTemplateGRPCClient := DirTemplatesGRPCClient + "grpc_client.go_" TableName := strings.ToLower(Table1.Name) @@ -72,24 +72,48 @@ func CreateFiles(Table1 *types.Table) error { if err != nil { log.Panic("ReadFile() ", FilenameTemplateGRPCClient, " error: ", err) } - TextDB := string(bytes) + TextGRPCClient := string(bytes) //создание текста ModelName := Table1.NameGo - TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) - TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) - TextDB = config.Settings.TEXT_MODULE_GENERATED + TextDB + TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) + TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) + TextGRPCClient = config.Settings.TEXT_MODULE_GENERATED + TextGRPCClient if config.Settings.HAS_IS_DELETED == true { - TextDB = DeleteFuncDelete(TextDB, ModelName, Table1) - //TextDB = DeleteFuncDeleteCtx(TextDB, ModelName, Table1) - TextDB = DeleteFuncRestore(TextDB, ModelName, Table1) - //TextDB = DeleteFuncRestoreCtx(TextDB, ModelName, Table1) + TextGRPCClient = DeleteFuncDelete(TextGRPCClient, ModelName, Table1) + //TextGRPCClient = DeleteFuncDeleteCtx(TextGRPCClient, ModelName, Table1) + TextGRPCClient = DeleteFuncRestore(TextGRPCClient, ModelName, Table1) + //TextGRPCClient = DeleteFuncRestoreCtx(TextGRPCClient, ModelName, Table1) + } + TextGRPCClient = DeleteFuncFind_byExtID(TextGRPCClient, ModelName, Table1) + + //замена импортов на новые URL + //TextGRPCClient = create_files.ReplaceServiceURLImports(TextGRPCClient) + + if config.Settings.USE_DEFAULT_TEMPLATE == true { + //TextGRPCServer = create_files.ReplaceServiceURLImports(TextGRPCServer) + TextGRPCClient = create_files.DeleteTemplateRepositoryImports(TextGRPCClient) + + //proto + RepositoryGRPCProtoURL := create_files.FindGRPCProtoURL() + TextGRPCClient = create_files.AddImport(TextGRPCClient, RepositoryGRPCProtoURL) + + //model + RepositoryModelURL := create_files.FindModelTableURL(TableName) + TextGRPCClient = create_files.AddImport(TextGRPCClient, RepositoryModelURL) + + //grpc client + RepositoryGRPCClientlURL := create_files.FindGRPClientURL() + TextGRPCClient = create_files.AddImport(TextGRPCClient, RepositoryGRPCClientlURL) + + //constants + RepositoryGRPCConstantsURL := create_files.FindGRPCConstantsURL() + TextGRPCClient = create_files.AddImport(TextGRPCClient, RepositoryGRPCConstantsURL) } - TextDB = DeleteFuncFind_byExtID(TextDB, ModelName, Table1) //запись файла - err = os.WriteFile(FilenameReadyGRPCClient, []byte(TextDB), constants.FILE_PERMISSIONS) + err = os.WriteFile(FilenameReadyGRPCClient, []byte(TextGRPCClient), constants.FILE_PERMISSIONS) return err } @@ -102,8 +126,8 @@ func CreateTestFiles(Table1 *types.Table) error { DirBin := micro.ProgramDir_bin() DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile() DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile() - DirTemplatesGRPCClient := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile() - DirReadyGRPCClient := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile() + DirTemplatesGRPCClient := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile() + DirReadyGRPCClient := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile() FilenameTemplateGRPCClient := DirTemplatesGRPCClient + "grpc_client_test.go_" TableName := strings.ToLower(Table1.Name) @@ -123,34 +147,37 @@ func CreateTestFiles(Table1 *types.Table) error { if err != nil { log.Panic("ReadFile() ", FilenameTemplateGRPCClient, " error: ", err) } - TextDB := string(bytes) + TextGRPCClient := string(bytes) //создание текста ModelName := Table1.NameGo - TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) - TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) - TextDB = config.Settings.TEXT_MODULE_GENERATED + TextDB + TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) + TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) + TextGRPCClient = config.Settings.TEXT_MODULE_GENERATED + TextGRPCClient if config.Settings.HAS_IS_DELETED == true { - TextDB = DeleteFuncTestDelete(TextDB, ModelName, Table1) - TextDB = DeleteFuncTestRestore(TextDB, ModelName, Table1) + TextGRPCClient = DeleteFuncTestDelete(TextGRPCClient, ModelName, Table1) + TextGRPCClient = DeleteFuncTestRestore(TextGRPCClient, ModelName, Table1) } - TextDB = DeleteFuncTestFind_byExtID(TextDB, ModelName, Table1) + TextGRPCClient = DeleteFuncTestFind_byExtID(TextGRPCClient, ModelName, Table1) //Postgres_ID_Test = ID Minimum if Table1.IDMinimum != "" { TextFind := "const Postgres_ID_Test = " - TextDB = strings.ReplaceAll(TextDB, TextFind+"1", TextFind+Table1.IDMinimum) + TextGRPCClient = strings.ReplaceAll(TextGRPCClient, TextFind+"1", TextFind+Table1.IDMinimum) } // замена ID на PrimaryKey - TextDB = create_files.ReplacePrimaryKeyID(TextDB, Table1) + TextGRPCClient = create_files.ReplacePrimaryKeyID(TextGRPCClient, Table1) //SkipNow() - TextDB = create_files.AddSkipNow(TextDB, Table1) + TextGRPCClient = create_files.AddSkipNow(TextGRPCClient, Table1) + + //замена импортов на новые URL + TextGRPCClient = create_files.ReplaceServiceURLImports(TextGRPCClient) //запись файла - err = os.WriteFile(FilenameReadyGRPCClient, []byte(TextDB), constants.FILE_PERMISSIONS) + err = os.WriteFile(FilenameReadyGRPCClient, []byte(TextGRPCClient), constants.FILE_PERMISSIONS) return err } diff --git a/internal/create_files/grpc_proto/grpc_proto.go b/internal/create_files/grpc_proto/grpc_proto.go index de75b1b..addae22 100644 --- a/internal/create_files/grpc_proto/grpc_proto.go +++ b/internal/create_files/grpc_proto/grpc_proto.go @@ -37,7 +37,7 @@ func CreateFileProto(MapAll map[string]*types.Table) error { DirReadyProto := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + micro.SeparatorFile() FilenameReadyProto := DirReadyProto + config.Settings.SERVICE_NAME + ".proto" - FilenameTemplateProto := DirTemplatesProto + "service.proto" + FilenameTemplateProto := DirTemplatesProto + "service.proto_" bytes, err := os.ReadFile(FilenameTemplateProto) if err != nil { log.Panic("ReadFile() ", FilenameTemplateProto, " error: ", err) diff --git a/internal/create_files/grpc_server/grpc_server.go b/internal/create_files/grpc_server/grpc_server.go index 2db569a..de566c2 100644 --- a/internal/create_files/grpc_server/grpc_server.go +++ b/internal/create_files/grpc_server/grpc_server.go @@ -62,27 +62,39 @@ func CreateFiles(Table1 *types.Table) error { if err != nil { log.Panic("ReadFile() ", FilenameTemplateGRPCServer, " error: ", err) } - TextDB := string(bytes) + TextGRPCServer := string(bytes) //создание текста ModelName := Table1.NameGo - TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) - TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) - TextDB = config.Settings.TEXT_MODULE_GENERATED + TextDB + TextGRPCServer = strings.ReplaceAll(TextGRPCServer, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) + TextGRPCServer = strings.ReplaceAll(TextGRPCServer, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) + TextGRPCServer = config.Settings.TEXT_MODULE_GENERATED + TextGRPCServer if config.Settings.USE_DEFAULT_TEMPLATE == true { if config.Settings.HAS_IS_DELETED == true { - TextDB = DeleteFuncDelete(TextDB, ModelName, Table1) - TextDB = DeleteFuncDeleteCtx(TextDB, ModelName, Table1) - TextDB = DeleteFuncRestore(TextDB, ModelName, Table1) - TextDB = DeleteFuncRestoreCtx(TextDB, ModelName, Table1) + TextGRPCServer = DeleteFuncDelete(TextGRPCServer, ModelName, Table1) + TextGRPCServer = DeleteFuncDeleteCtx(TextGRPCServer, ModelName, Table1) + TextGRPCServer = DeleteFuncRestore(TextGRPCServer, ModelName, Table1) + TextGRPCServer = DeleteFuncRestoreCtx(TextGRPCServer, ModelName, Table1) } - TextDB = DeleteFuncFind_byExtID(TextDB, ModelName, Table1) - TextDB = ConvertID(TextDB, Table1) + TextGRPCServer = DeleteFuncFind_byExtID(TextGRPCServer, ModelName, Table1) + TextGRPCServer = ConvertID(TextGRPCServer, Table1) + + //замена импортов на новые URL + //TextGRPCServer = create_files.ReplaceServiceURLImports(TextGRPCServer) + TextGRPCServer = create_files.DeleteTemplateRepositoryImports(TextGRPCServer) + + //proto + RepositoryGRPCProtoURL := create_files.FindGRPCProtoURL() + TextGRPCServer = create_files.AddImport(TextGRPCServer, RepositoryGRPCProtoURL) + + //model + RepositoryModelURL := create_files.FindModelTableURL(TableName) + TextGRPCServer = create_files.AddImport(TextGRPCServer, RepositoryModelURL) } //запись файла - err = os.WriteFile(FilenameReadyGRPCServer, []byte(TextDB), constants.FILE_PERMISSIONS) + err = os.WriteFile(FilenameReadyGRPCServer, []byte(TextGRPCServer), constants.FILE_PERMISSIONS) return err } @@ -107,34 +119,37 @@ func CreateTestFiles(Table1 *types.Table) error { if err != nil { log.Panic("ReadFile() ", FilenameTemplateGRPCServer, " error: ", err) } - TextDB := string(bytes) + TextGRPCServer := string(bytes) //создание текста ModelName := Table1.NameGo - TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) - TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) - TextDB = config.Settings.TEXT_MODULE_GENERATED + TextDB + TextGRPCServer = strings.ReplaceAll(TextGRPCServer, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) + TextGRPCServer = strings.ReplaceAll(TextGRPCServer, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) + TextGRPCServer = config.Settings.TEXT_MODULE_GENERATED + TextGRPCServer if config.Settings.HAS_IS_DELETED == true { - TextDB = DeleteFuncTestDelete(TextDB, ModelName, Table1) - TextDB = DeleteFuncTestRestore(TextDB, ModelName, Table1) + TextGRPCServer = DeleteFuncTestDelete(TextGRPCServer, ModelName, Table1) + TextGRPCServer = DeleteFuncTestRestore(TextGRPCServer, ModelName, Table1) } - TextDB = DeleteFuncTestFind_byExtID(TextDB, ModelName, Table1) + TextGRPCServer = DeleteFuncTestFind_byExtID(TextGRPCServer, ModelName, Table1) //Postgres_ID_Test = ID Minimum if Table1.IDMinimum != "" { TextFind := "const " + ModelName + "_ID_Test = " - TextDB = strings.ReplaceAll(TextDB, TextFind+"1", TextFind+Table1.IDMinimum) + TextGRPCServer = strings.ReplaceAll(TextGRPCServer, TextFind+"1", TextFind+Table1.IDMinimum) } // замена ID на PrimaryKey - TextDB = create_files.ReplacePrimaryKeyID(TextDB, Table1) + TextGRPCServer = create_files.ReplacePrimaryKeyID(TextGRPCServer, Table1) //SkipNow() - TextDB = create_files.AddSkipNow(TextDB, Table1) + TextGRPCServer = create_files.AddSkipNow(TextGRPCServer, Table1) + + //замена импортов на новые URL + TextGRPCServer = create_files.ReplaceServiceURLImports(TextGRPCServer) //запись файла - err = os.WriteFile(FilenameReadyGRPCServer, []byte(TextDB), constants.FILE_PERMISSIONS) + err = os.WriteFile(FilenameReadyGRPCServer, []byte(TextGRPCServer), constants.FILE_PERMISSIONS) return err } diff --git a/internal/create_files/main_file/main_file.go b/internal/create_files/main_file/main_file.go index 2e1c755..fccd9eb 100644 --- a/internal/create_files/main_file/main_file.go +++ b/internal/create_files/main_file/main_file.go @@ -64,6 +64,9 @@ func CreateFileMain() error { } } + //замена импортов на новые URL + TextMain = create_files.ReplaceServiceURLImports(TextMain) + //запись файла err = os.WriteFile(FilenameReadyMain, []byte(TextMain), constants.FILE_PERMISSIONS) diff --git a/internal/create_files/makefile/makefile.go b/internal/create_files/makefile/makefile.go new file mode 100644 index 0000000..2d37486 --- /dev/null +++ b/internal/create_files/makefile/makefile.go @@ -0,0 +1,59 @@ +package makefile + +import ( + "github.com/ManyakRus/crud_generator/internal/config" + "github.com/ManyakRus/crud_generator/internal/constants" + "github.com/ManyakRus/crud_generator/internal/folders" + "github.com/ManyakRus/starter/log" + "github.com/ManyakRus/starter/micro" + "os" + "strings" +) + +// CreateAllFiles - создаёт файл makefile в корне проекта +func CreateAllFiles() error { + var err error + + err = CreateMakefile() + if err != nil { + log.Error("CreateMakefile() error: ", err) + return err + } + + return err +} + +// CreateMakefile - создаёт 1 файл в папке grpc +func CreateMakefile() error { + var err error + + if config.Settings.USE_DEFAULT_TEMPLATE == false { + return err + } + + //чтение файлов + DirBin := micro.ProgramDir_bin() + DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile() + DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile() + DirTemplatesMakefile := DirTemplates + DirReadyMakefile := DirReady + FilenameReadyMakefile := DirReadyMakefile + "Makefile" + FilenameTemplateMakefile := DirTemplatesMakefile + "Makefile_" + + bytes, err := os.ReadFile(FilenameTemplateMakefile) + if err != nil { + log.Panic("ReadFile() ", FilenameTemplateMakefile, " error: ", err) + } + TextMakefile := string(bytes) + + //создадим папку ready + folders.CreateFolder(DirReadyMakefile) + + //ReplaceAll + TextMakefile = strings.ReplaceAll(TextMakefile, config.Settings.TEMPLATE_SERVICE_NAME, strings.ToLower(config.Settings.SERVICE_NAME)) + + //запись файла + err = os.WriteFile(FilenameReadyMakefile, []byte(TextMakefile), constants.FILE_PERMISSIONS) + + return err +} diff --git a/internal/create_files/makefile/makefile_test.go b/internal/create_files/makefile/makefile_test.go new file mode 100644 index 0000000..5303a80 --- /dev/null +++ b/internal/create_files/makefile/makefile_test.go @@ -0,0 +1 @@ +package makefile diff --git a/internal/create_files/model/model.go b/internal/create_files/model/model.go index 6fcd889..c7eaa4b 100644 --- a/internal/create_files/model/model.go +++ b/internal/create_files/model/model.go @@ -104,6 +104,9 @@ func CreateFilesModel_struct(Table1 *types.Table, DirTemplatesModel, DirReadyMod TextModel = create_files.CheckAndAddImportTime_FromText(TextModel) TextModel = create_files.DeleteImportModel(TextModel) + //замена импортов на новые URL + TextModel = create_files.ReplaceServiceURLImports(TextModel) + //запись файла err = os.WriteFile(FilenameReadyModel, []byte(TextModel), constants.FILE_PERMISSIONS) @@ -143,6 +146,9 @@ func CreateFilesModel_crud(Table1 *types.Table, DirTemplatesModel, DirReadyModel TextModel = create_files.CheckAndAddImportTime_FromText(TextModel) TextModel = create_files.DeleteImportModel(TextModel) + //замена импортов на новые URL + TextModel = create_files.ReplaceServiceURLImports(TextModel) + //запись файла err = os.WriteFile(FilenameReadyModel, []byte(TextModel), constants.FILE_PERMISSIONS) diff --git a/internal/create_files/nrpc_client/nrpc_client.go b/internal/create_files/nrpc_client/nrpc_client.go index 17c01a5..135fe28 100644 --- a/internal/create_files/nrpc_client/nrpc_client.go +++ b/internal/create_files/nrpc_client/nrpc_client.go @@ -71,24 +71,27 @@ func CreateFiles(Table1 *types.Table) error { if err != nil { log.Panic("ReadFile() ", FilenameTemplateNRPCClient, " error: ", err) } - TextDB := string(bytes) + TextNRPCClient := string(bytes) //создание текста ModelName := Table1.NameGo - TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) - TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) - TextDB = config.Settings.TEXT_MODULE_GENERATED + TextDB + TextNRPCClient = strings.ReplaceAll(TextNRPCClient, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) + TextNRPCClient = strings.ReplaceAll(TextNRPCClient, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) + TextNRPCClient = config.Settings.TEXT_MODULE_GENERATED + TextNRPCClient if config.Settings.HAS_IS_DELETED == true { - TextDB = DeleteFuncDelete(TextDB, ModelName, Table1) - //TextDB = DeleteFuncDeleteCtx(TextDB, ModelName, Table1) - TextDB = DeleteFuncRestore(TextDB, ModelName, Table1) - //TextDB = DeleteFuncRestoreCtx(TextDB, ModelName, Table1) + TextNRPCClient = DeleteFuncDelete(TextNRPCClient, ModelName, Table1) + //TextNRPCClient = DeleteFuncDeleteCtx(TextNRPCClient, ModelName, Table1) + TextNRPCClient = DeleteFuncRestore(TextNRPCClient, ModelName, Table1) + //TextNRPCClient = DeleteFuncRestoreCtx(TextNRPCClient, ModelName, Table1) } - TextDB = DeleteFuncFind_byExtID(TextDB, ModelName, Table1) + TextNRPCClient = DeleteFuncFind_byExtID(TextNRPCClient, ModelName, Table1) + + //замена импортов на новые URL + TextNRPCClient = create_files.ReplaceServiceURLImports(TextNRPCClient) //запись файла - err = os.WriteFile(FilenameReadyNRPCClient, []byte(TextDB), constants.FILE_PERMISSIONS) + err = os.WriteFile(FilenameReadyNRPCClient, []byte(TextNRPCClient), constants.FILE_PERMISSIONS) return err } @@ -122,34 +125,37 @@ func CreateTestFiles(Table1 *types.Table) error { if err != nil { log.Panic("ReadFile() ", FilenameTemplateNRPCClient, " error: ", err) } - TextDB := string(bytes) + TextNRPCClient := string(bytes) //создание текста ModelName := Table1.NameGo - TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) - TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) - TextDB = config.Settings.TEXT_MODULE_GENERATED + TextDB + TextNRPCClient = strings.ReplaceAll(TextNRPCClient, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) + TextNRPCClient = strings.ReplaceAll(TextNRPCClient, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) + TextNRPCClient = config.Settings.TEXT_MODULE_GENERATED + TextNRPCClient if config.Settings.HAS_IS_DELETED == true { - TextDB = DeleteFuncTestDelete(TextDB, ModelName, Table1) - TextDB = DeleteFuncTestRestore(TextDB, ModelName, Table1) + TextNRPCClient = DeleteFuncTestDelete(TextNRPCClient, ModelName, Table1) + TextNRPCClient = DeleteFuncTestRestore(TextNRPCClient, ModelName, Table1) } - TextDB = DeleteFuncTestFind_byExtID(TextDB, ModelName, Table1) + TextNRPCClient = DeleteFuncTestFind_byExtID(TextNRPCClient, ModelName, Table1) //Postgres_ID_Test = ID Minimum if Table1.IDMinimum != "" { TextFind := "const Postgres_ID_Test = " - TextDB = strings.ReplaceAll(TextDB, TextFind+"1", TextFind+Table1.IDMinimum) + TextNRPCClient = strings.ReplaceAll(TextNRPCClient, TextFind+"1", TextFind+Table1.IDMinimum) } // замена ID на PrimaryKey - TextDB = create_files.ReplacePrimaryKeyID(TextDB, Table1) + TextNRPCClient = create_files.ReplacePrimaryKeyID(TextNRPCClient, Table1) //SkipNow() - TextDB = create_files.AddSkipNow(TextDB, Table1) + TextNRPCClient = create_files.AddSkipNow(TextNRPCClient, Table1) + + //замена импортов на новые URL + TextNRPCClient = create_files.ReplaceServiceURLImports(TextNRPCClient) //запись файла - err = os.WriteFile(FilenameReadyNRPCClient, []byte(TextDB), constants.FILE_PERMISSIONS) + err = os.WriteFile(FilenameReadyNRPCClient, []byte(TextNRPCClient), constants.FILE_PERMISSIONS) return err } diff --git a/internal/create_files/server_grpc_starter/server_grpc_starter.go b/internal/create_files/server_grpc_starter/server_grpc_starter.go index e372444..d4e5a62 100644 --- a/internal/create_files/server_grpc_starter/server_grpc_starter.go +++ b/internal/create_files/server_grpc_starter/server_grpc_starter.go @@ -51,6 +51,8 @@ func CreateServerGRPCStarter() error { folders.CreateFolder(DirReadyServerGRPC) if config.Settings.USE_DEFAULT_TEMPLATE == true { + TextGRPCStarter = create_files.DeleteTemplateRepositoryImports(TextGRPCStarter) + //заменим имя сервиса на новое ServiceNameTemplate := config.Settings.TEMPLATE_SERVICE_NAME ServiceName := config.Settings.SERVICE_NAME @@ -63,8 +65,8 @@ func CreateServerGRPCStarter() error { TextGRPCStarter = strings.ReplaceAll(TextGRPCStarter, ServiceNameTemplate, ServiceName) TextGRPCStarter = strings.ReplaceAll(TextGRPCStarter, micro.StringFromUpperCase(ServiceNameTemplate), micro.StringFromUpperCase(ServiceName)) - TextGRPCStarter = create_files.DeleteTemplateRepositoryImports(TextGRPCStarter) - ProtoURL := create_files.FindProtoURL() + "/grpc_proto" + //proto + ProtoURL := create_files.FindGRPCProtoURL() TextGRPCStarter = create_files.AddImport(TextGRPCStarter, ProtoURL) } diff --git a/internal/create_files/server_nrpc_starter/server_nrpc_starter.go b/internal/create_files/server_nrpc_starter/server_nrpc_starter.go index 48b1ba5..52041a1 100644 --- a/internal/create_files/server_nrpc_starter/server_nrpc_starter.go +++ b/internal/create_files/server_nrpc_starter/server_nrpc_starter.go @@ -8,7 +8,6 @@ import ( "github.com/ManyakRus/starter/log" "github.com/ManyakRus/starter/micro" "os" - "strings" ) // CreateAllFiles - создаёт все файлы в папке grpc proto @@ -52,18 +51,26 @@ func CreateServerGRPCStarter() error { if config.Settings.USE_DEFAULT_TEMPLATE == true { //заменим имя сервиса на новое - ServiceNameTemplate := config.Settings.TEMPLATE_SERVICE_NAME - ServiceName := config.Settings.SERVICE_NAME - TextNRPCStarter = strings.ReplaceAll(TextNRPCStarter, ServiceNameTemplate, ServiceName) - TextNRPCStarter = strings.ReplaceAll(TextNRPCStarter, micro.StringFromUpperCase(ServiceNameTemplate), micro.StringFromUpperCase(ServiceName)) + //ServiceNameTemplate := config.Settings.TEMPLATE_SERVICE_NAME + //ServiceName := config.Settings.SERVICE_NAME + //TextNRPCStarter = strings.ReplaceAll(TextNRPCStarter, ServiceNameTemplate, ServiceName) + //TextNRPCStarter = strings.ReplaceAll(TextNRPCStarter, micro.StringFromUpperCase(ServiceNameTemplate), micro.StringFromUpperCase(ServiceName)) TextNRPCStarter = create_files.DeleteTemplateRepositoryImports(TextNRPCStarter) - ProtoURL := create_files.FindProtoURL() + "/grpc_proto" - TextNRPCStarter = create_files.AddImport(TextNRPCStarter, ProtoURL) + //ProtoURL := create_files.FindProtoURL() + "/grpc_proto" + //TextNRPCStarter = create_files.AddImport(TextNRPCStarter, ProtoURL) + // + //GRPCServer_URL := create_files.FindGRPCServerlURL() + //TextNRPCStarter = create_files.AddImport(TextNRPCStarter, GRPCServer_URL) - GRPCServer_URL := create_files.FindGRPCServerlURL() - TextNRPCStarter = create_files.AddImport(TextNRPCStarter, GRPCServer_URL) + //Proto URL + RepositoryProtoURL := create_files.FindGRPCProtoURL() + TextNRPCStarter = create_files.AddImport(TextNRPCStarter, RepositoryProtoURL) + + //server grpc URL + RepositoryServerGRPCURL := create_files.FindGRPCServerlURL() + TextNRPCStarter = create_files.AddImport(TextNRPCStarter, RepositoryServerGRPCURL) } //запись файла diff --git a/internal/folders/folders.go b/internal/folders/folders.go index 2ea214b..914a318 100644 --- a/internal/folders/folders.go +++ b/internal/folders/folders.go @@ -158,16 +158,16 @@ func CreateAllFolders() { log.Info("CreateFolder_err() ", Filename) } - //grpc client - Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT - ok, err = micro.FileExists(Filename) - if ok == false || err != nil { - err = CreateFolder_err(Filename, 0777) - if err != nil { - log.Panic("CreateFolder_err() ", Filename, " error: ", err) - } - log.Info("CreateFolder_err() ", Filename) - } + ////grpc client + //Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + //ok, err = micro.FileExists(Filename) + //if ok == false || err != nil { + // err = CreateFolder_err(Filename, 0777) + // if err != nil { + // log.Panic("CreateFolder_err() ", Filename, " error: ", err) + // } + // log.Info("CreateFolder_err() ", Filename) + //} //grpc_proto Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + micro.SeparatorFile() + "grpc_proto" diff --git a/internal/logic/logic.go b/internal/logic/logic.go index 509a74b..8f3e8e1 100644 --- a/internal/logic/logic.go +++ b/internal/logic/logic.go @@ -4,10 +4,12 @@ import ( "github.com/ManyakRus/crud_generator/internal/config" "github.com/ManyakRus/crud_generator/internal/create_files/crud_starter" "github.com/ManyakRus/crud_generator/internal/create_files/db" + "github.com/ManyakRus/crud_generator/internal/create_files/generation_code_sh" "github.com/ManyakRus/crud_generator/internal/create_files/grpc_client" "github.com/ManyakRus/crud_generator/internal/create_files/grpc_proto" "github.com/ManyakRus/crud_generator/internal/create_files/grpc_server" "github.com/ManyakRus/crud_generator/internal/create_files/main_file" + "github.com/ManyakRus/crud_generator/internal/create_files/makefile" "github.com/ManyakRus/crud_generator/internal/create_files/model" "github.com/ManyakRus/crud_generator/internal/create_files/nrpc_client" "github.com/ManyakRus/crud_generator/internal/create_files/server_grpc_starter" @@ -101,20 +103,17 @@ func StartFillAll() error { return err } + //makefile + err = makefile.CreateAllFiles() + if err != nil { + return err + } + + //generation_code.sh + err = generation_code_sh.CreateAllFiles() + if err != nil { + return err + } + return err } - -//// MassFromMapColumns - возвращает Slice из Map -//func MassFromMapColumns(MapColumns map[string]types.Column) []types.Column { -// Otvet := make([]types.Column, 0) -// -// for _, v := range MapColumns { -// Otvet = append(Otvet, v) -// } -// -// sort.Slice(Otvet[:], func(i, j int) bool { -// return Otvet[i].OrderNumber < Otvet[j].OrderNumber -// }) -// -// return Otvet -//} diff --git a/scripts/VersionToFile.py b/scripts/VersionToFile.py new file mode 100755 index 0000000..c768562 --- /dev/null +++ b/scripts/VersionToFile.py @@ -0,0 +1,52 @@ +#!/usr/bin/python3 +# Python script to create an empty file +# with current date as name. + +# importing datetime module +from datetime import datetime +import os + +# datetime.datetime.now() to get +# current date as filename. +# TimeNow = datetime.datetime.now() + +FILESUBVERSION="../bin/subversion.txt" +FILEDATE="../bin/date.txt" + +# create empty file +def create_file(): + fmt = "%Y-%m-%d %H:%M:%S.%f" + str1 = datetime.utcnow().strftime(fmt)[:-3] + + # Function creates an empty file + # %d - date, %B - month, %Y - Year + with open(FILEDATE, "w") as file: + file.write(str1) + file.close() + +def set_version(): + filename=FILESUBVERSION + build=0 + mode = 'r' if os.path.exists(filename) else 'w+' + with open(filename, encoding="utf8", mode=mode) as file_in: + _str_build = file_in.read() + file_in.close() + try: + build = int(_str_build) + except ValueError as err: + print("Build.__setVers(): при конвертировании строки в число, err=", err) + finally: + pass + build += 1 + str_build = str(build) + while len(str_build) < 5: + str_build = "0" + str_build + print("Build.set_version(): new build=", str_build) + with open(filename, "w", encoding="utf8") as file_in: + file_in.write(str_build) + file_in.close() + + +# Driver Code +create_file() +set_version() \ No newline at end of file diff --git a/cmd/test_copy/VersionToFile.py b/scripts/test_copy/VersionToFile.py similarity index 100% rename from cmd/test_copy/VersionToFile.py rename to scripts/test_copy/VersionToFile.py diff --git a/cmd/test_copy/date.txt b/scripts/test_copy/date.txt similarity index 100% rename from cmd/test_copy/date.txt rename to scripts/test_copy/date.txt diff --git a/cmd/test_copy/subversion.txt b/scripts/test_copy/subversion.txt similarity index 100% rename from cmd/test_copy/subversion.txt rename to scripts/test_copy/subversion.txt diff --git a/scripts/test_copy/version.txt b/scripts/test_copy/version.txt new file mode 100644 index 0000000..a5e11e5 --- /dev/null +++ b/scripts/test_copy/version.txt @@ -0,0 +1 @@ +v0 \ No newline at end of file