From 9f0ef9d535a1140633e94ffe0ea535d89bb0b8ed Mon Sep 17 00:00:00 2001 From: Nikitin Aleksandr Date: Tue, 20 Feb 2024 17:14:48 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20TEMPLATE?= =?UTF-8?q?S=5FGRPC=5FSERVER=5FTABLE=5FUPDATE=5FFILENAME?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/templates/configs_/settings.txt | 7 ++ .../server_grpc/server_grpc_table_update.go_ | 8 ++ .../server_grpc_table_update_test.go_ | 10 ++ internal/config/config.go | 11 +++ .../db_crud_tables/db_crud_tables.go | 14 ++- .../grpc_client_tables/grpc_client_tables.go | 18 ++-- .../grpc_server_tables/grpc_server_tables.go | 98 ++++++++++++------- 7 files changed, 120 insertions(+), 46 deletions(-) create mode 100644 bin/templates/internal/app/grpc/server_grpc/server_grpc_table_update.go_ create mode 100644 bin/templates/internal/app/grpc/server_grpc/server_grpc_table_update_test.go_ diff --git a/bin/templates/configs_/settings.txt b/bin/templates/configs_/settings.txt index dde5e45..205ebc0 100644 --- a/bin/templates/configs_/settings.txt +++ b/bin/templates/configs_/settings.txt @@ -207,3 +207,10 @@ TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_FILENAME="grpc_client_table_update.go_" #TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_TEST_FILENAME - short filename of "grpc_client_table_update_test.go_" file TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_TEST_FILENAME="grpc_client_table_update_test.go_" + +#TEMPLATES_GRPC_SERVER_TABLE_UPDATE_FILENAME - short filename of "server_grpc_table_update.go_" file +TEMPLATES_GRPC_SERVER_TABLE_UPDATE_FILENAME="server_grpc_table_update.go_" + +#TEMPLATES_GRPC_SERVER_TABLE_UPDATE_TEST_FILENAME - short filename of "server_grpc_table_update_test.go_" file +TEMPLATES_GRPC_SERVER_TABLE_UPDATE_TEST_FILENAME="server_grpc_table_update_test.go_" + diff --git a/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_update.go_ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_update.go_ new file mode 100644 index 0000000..cdce422 --- /dev/null +++ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_update.go_ @@ -0,0 +1,8 @@ +package server_grpc + +import ( + "context" + "github.com/ManyakRus/starter/micro" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/api/grpc_proto" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types" +) diff --git a/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_update_test.go_ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_update_test.go_ new file mode 100644 index 0000000..a85bb8c --- /dev/null +++ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_table_update_test.go_ @@ -0,0 +1,10 @@ +package server_grpc + +import ( + "context" + "github.com/ManyakRus/starter/config_main" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/api/grpc_proto" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/crud_starter" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types" + "testing" +) diff --git a/internal/config/config.go b/internal/config/config.go index 891c80e..d794b63 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -50,6 +50,8 @@ type SettingsINI struct { TEMPLATES_CRUD_TABLE_UPDATE_TEST_FILENAME string TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_FILENAME string TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_TEST_FILENAME string + TEMPLATES_GRPC_SERVER_TABLE_UPDATE_FILENAME string + TEMPLATES_GRPC_SERVER_TABLE_UPDATE_TEST_FILENAME string NEED_CREATE_MODEL_STRUCT bool NEED_CREATE_MODEL_CRUD bool NEED_CREATE_DB bool @@ -438,6 +440,15 @@ func FillSettings() { s = Getenv(Name, true) Settings.TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_TEST_FILENAME = s + // + Name = "TEMPLATES_GRPC_SERVER_TABLE_UPDATE_FILENAME" + s = Getenv(Name, true) + Settings.TEMPLATES_GRPC_SERVER_TABLE_UPDATE_FILENAME = s + + // + Name = "TEMPLATES_GRPC_SERVER_TABLE_UPDATE_TEST_FILENAME" + s = Getenv(Name, true) + Settings.TEMPLATES_GRPC_SERVER_TABLE_UPDATE_TEST_FILENAME = s } // CurrentDirectory - возвращает текущую директорию ОС diff --git a/internal/create_files/db_crud_tables/db_crud_tables.go b/internal/create_files/db_crud_tables/db_crud_tables.go index 3159e29..07b3085 100644 --- a/internal/create_files/db_crud_tables/db_crud_tables.go +++ b/internal/create_files/db_crud_tables/db_crud_tables.go @@ -516,6 +516,8 @@ func CreateFilesUpdateEveryColumn(Table1 *types.Table) error { //заменим импорты if config.Settings.USE_DEFAULT_TEMPLATE == true { + TextCrud = create_files.DeleteTemplateRepositoryImports(TextCrud) + DBConstantsURL := create_files.FindDBConstantsURL() TextCrud = create_files.AddImport(TextCrud, DBConstantsURL) @@ -667,12 +669,14 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error { //` //заменим импорты - //if config.Settings.USE_DEFAULT_TEMPLATE == true { - ModelTableURL := create_files.FindModelTableURL(TableName) - TextCrud = create_files.AddImport(TextCrud, ModelTableURL) + if config.Settings.USE_DEFAULT_TEMPLATE == true { + TextCrud = create_files.DeleteTemplateRepositoryImports(TextCrud) - //TextCrud = create_files.ConvertIdToAlias(TextCrud, Table1) - //} + ModelTableURL := create_files.FindModelTableURL(TableName) + TextCrud = create_files.AddImport(TextCrud, ModelTableURL) + + //TextCrud = create_files.ConvertIdToAlias(TextCrud, Table1) + } //создание текста TextUpdateEveryColumn := FindTextUpdateEveryColumnTest(TextCrudUpdateFunc, Table1) diff --git a/internal/create_files/grpc_client_tables/grpc_client_tables.go b/internal/create_files/grpc_client_tables/grpc_client_tables.go index e875494..1908c10 100644 --- a/internal/create_files/grpc_client_tables/grpc_client_tables.go +++ b/internal/create_files/grpc_client_tables/grpc_client_tables.go @@ -409,6 +409,8 @@ func CreateFilesUpdateEveryColumn(Table1 *types.Table) error { //заменим импорты if config.Settings.USE_DEFAULT_TEMPLATE == true { + TextGRPC_Client = create_files.DeleteTemplateRepositoryImports(TextGRPC_Client) + ProtoURL := create_files.FindProtoURL() TextGRPC_Client = create_files.AddImport(TextGRPC_Client, ProtoURL) @@ -565,15 +567,17 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error { //` //заменим импорты - //if config.Settings.USE_DEFAULT_TEMPLATE == true { - GRPCClientURL := create_files.FindGRPClientURL() - TextGRPC_Client = create_files.AddImport(TextGRPC_Client, GRPCClientURL) + if config.Settings.USE_DEFAULT_TEMPLATE == true { + TextGRPC_Client = create_files.DeleteTemplateRepositoryImports(TextGRPC_Client) - ModelTableURL := create_files.FindModelTableURL(TableName) - TextGRPC_Client = create_files.AddImport(TextGRPC_Client, ModelTableURL) + GRPCClientURL := create_files.FindGRPClientURL() + TextGRPC_Client = create_files.AddImport(TextGRPC_Client, GRPCClientURL) - //TextGRPC_Client = create_files.ConvertIdToAlias(TextGRPC_Client, Table1) - //} + ModelTableURL := create_files.FindModelTableURL(TableName) + TextGRPC_Client = create_files.AddImport(TextGRPC_Client, ModelTableURL) + + //TextGRPC_Client = create_files.ConvertIdToAlias(TextGRPC_Client, Table1) + } //создание текста TextUpdateEveryColumn := FindTextUpdateEveryColumnTest(TextGRPC_Client_UpdateFunc, Table1) diff --git a/internal/create_files/grpc_server_tables/grpc_server_tables.go b/internal/create_files/grpc_server_tables/grpc_server_tables.go index 8b1146c..1959d80 100644 --- a/internal/create_files/grpc_server_tables/grpc_server_tables.go +++ b/internal/create_files/grpc_server_tables/grpc_server_tables.go @@ -349,31 +349,46 @@ func CreateFilesUpdateEveryColumn(Table1 *types.Table) error { DirTemplatesGRPCServer := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_GRPC_SERVER + micro.SeparatorFile() DirReadyGRPCServer := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_SERVER + micro.SeparatorFile() - FilenameTemplateGRPCServer := DirTemplatesGRPCServer + constants.SERVER_GRPC_TABLE_UPDATE_FUNC_FILENAME + FilenameTemplateGRPCServerFunc := DirTemplatesGRPCServer + constants.SERVER_GRPC_TABLE_UPDATE_FUNC_FILENAME TableName := strings.ToLower(Table1.Name) DirReadyTable := DirReadyGRPCServer - FilenameReadyGRPCServerUpdate := DirReadyTable + config.Settings.PREFIX_SERVER_GRPC + TableName + "_update.go" + FilenameReadyGRPCServerUpdateFunc := DirReadyTable + config.Settings.PREFIX_SERVER_GRPC + TableName + "_update.go" //создадим папку готовых файлов folders.CreateFolder(DirReadyTable) - bytes, err := os.ReadFile(FilenameTemplateGRPCServer) + //читаем шаблон файла, только функции + bytes, err := os.ReadFile(FilenameTemplateGRPCServerFunc) if err != nil { - log.Panic("ReadFile() ", FilenameTemplateGRPCServer, " error: ", err) + log.Panic("ReadFile() ", FilenameTemplateGRPCServerFunc, " error: ", err) } TextGRPCServerUpdateFunc := string(bytes) - PackageName := micro.LastWord(config.Settings.TEMPLATE_FOLDERNAME_GRPC_SERVER) - TextGRPCServer := "package " + PackageName + "\n\n" - TextGRPCServer = TextGRPCServer + `import ( - "context" - "github.com/ManyakRus/starter/micro" -) + //читаем шаблон файла, без функций + FilenameTemplateGRPCServerUpdate := DirTemplatesGRPCServer + config.Settings.TEMPLATES_GRPC_SERVER_TABLE_UPDATE_FILENAME + bytes, err = os.ReadFile(FilenameTemplateGRPCServerUpdate) + if err != nil { + log.Panic("ReadFile() ", FilenameTemplateGRPCServerUpdate, " error: ", err) + } + TextGRPCServer := string(bytes) + TextGRPCServer = TextGRPCServer + "\n" -` + //заменим имя пакета на новое + TextGRPCServer = create_files.ReplacePackageName(TextGRPCServer, DirReadyTable) + + // PackageName := micro.LastWord(config.Settings.TEMPLATE_FOLDERNAME_GRPC_SERVER) + // TextGRPCServer := "package " + PackageName + "\n\n" + // TextGRPCServer = TextGRPCServer + `import ( + // "context" + // "github.com/ManyakRus/starter/micro" + //) + // + //` //заменим импорты if config.Settings.USE_DEFAULT_TEMPLATE == true { + TextGRPCServer = create_files.DeleteTemplateRepositoryImports(TextGRPCServer) + ModelTableURL := create_files.FindModelTableURL(TableName) TextGRPCServer = create_files.AddImport(TextGRPCServer, ModelTableURL) @@ -410,7 +425,7 @@ func CreateFilesUpdateEveryColumn(Table1 *types.Table) error { TextGRPCServer = create_files.DeleteEmptyLines(TextGRPCServer) //запись файла - err = os.WriteFile(FilenameReadyGRPCServerUpdate, []byte(TextGRPCServer), constants.FILE_PERMISSIONS) + err = os.WriteFile(FilenameReadyGRPCServerUpdateFunc, []byte(TextGRPCServer), constants.FILE_PERMISSIONS) return err } @@ -478,7 +493,7 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error { DirTemplatesGRPCServer := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_GRPC_SERVER + micro.SeparatorFile() DirReadyGRPCServer := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_SERVER + micro.SeparatorFile() - FilenameTemplateGRPCServer := DirTemplatesGRPCServer + constants.SERVER_GRPC_TABLE_UPDATE_FUNC_TEST_FILENAME + FilenameTemplateGRPCServerFunc := DirTemplatesGRPCServer + constants.SERVER_GRPC_TABLE_UPDATE_FUNC_TEST_FILENAME TableName := strings.ToLower(Table1.Name) DirReadyTable := DirReadyGRPCServer FilenameReadyGRPCServerUpdate := DirReadyTable + config.Settings.PREFIX_SERVER_GRPC + TableName + "_update_test.go" @@ -486,38 +501,53 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error { //создадим папку готовых файлов folders.CreateFolder(DirReadyTable) - bytes, err := os.ReadFile(FilenameTemplateGRPCServer) + //читаем шаблон файла, только функции + bytes, err := os.ReadFile(FilenameTemplateGRPCServerFunc) if err != nil { - log.Panic("ReadFile() ", FilenameTemplateGRPCServer, " error: ", err) + log.Panic("ReadFile() ", FilenameTemplateGRPCServerFunc, " error: ", err) } TextGRPCServerUpdateFunc := string(bytes) - PackageName := micro.LastWord(config.Settings.TEMPLATE_FOLDERNAME_GRPC_SERVER) - TextGRPCServer := "package " + PackageName + "\n\n" - TextGRPCServer = TextGRPCServer + `import ( - "context" - "testing" - "github.com/ManyakRus/starter/config_main" -) + //читаем шаблон файла, без функций + FilenameTemplateGRPCServerUpdate := DirTemplatesGRPCServer + config.Settings.TEMPLATES_GRPC_SERVER_TABLE_UPDATE_TEST_FILENAME + bytes, err = os.ReadFile(FilenameTemplateGRPCServerUpdate) + if err != nil { + log.Panic("ReadFile() ", FilenameTemplateGRPCServerUpdate, " error: ", err) + } + TextGRPCServer := string(bytes) + TextGRPCServer = TextGRPCServer + "\n" -` + //заменим имя пакета на новое + TextGRPCServer = create_files.ReplacePackageName(TextGRPCServer, DirReadyTable) + + // PackageName := micro.LastWord(config.Settings.TEMPLATE_FOLDERNAME_GRPC_SERVER) + // TextGRPCServer := "package " + PackageName + "\n\n" + // TextGRPCServer = TextGRPCServer + `import ( + // "context" + // "testing" + // "github.com/ManyakRus/starter/config_main" + //) + // + //` //заменим импорты - //if config.Settings.USE_DEFAULT_TEMPLATE == true { - ModelTableURL := create_files.FindModelTableURL(TableName) - TextGRPCServer = create_files.AddImport(TextGRPCServer, ModelTableURL) + if config.Settings.USE_DEFAULT_TEMPLATE == true { + TextGRPCServer = create_files.DeleteTemplateRepositoryImports(TextGRPCServer) - ProtoURL := create_files.FindProtoURL() - TextGRPCServer = create_files.AddImport(TextGRPCServer, ProtoURL) + ModelTableURL := create_files.FindModelTableURL(TableName) + TextGRPCServer = create_files.AddImport(TextGRPCServer, ModelTableURL) - //ModelURL := create_files.FindModelURL() - //TextGRPCServer = create_files.AddImport(TextGRPCServer, ModelURL) + ProtoURL := create_files.FindProtoURL() + TextGRPCServer = create_files.AddImport(TextGRPCServer, ProtoURL) - CrudStarterURL := create_files.FindCrudStarterURL() - TextGRPCServer = create_files.AddImport(TextGRPCServer, CrudStarterURL) + //ModelURL := create_files.FindModelURL() + //TextGRPCServer = create_files.AddImport(TextGRPCServer, ModelURL) - //TextGRPCServer = create_files.ConvertIdToAlias(TextGRPCServer, Table1) - //} + CrudStarterURL := create_files.FindCrudStarterURL() + TextGRPCServer = create_files.AddImport(TextGRPCServer, CrudStarterURL) + + //TextGRPCServer = create_files.ConvertIdToAlias(TextGRPCServer, Table1) + } //создание текста TextUpdateEveryColumn := FindTextUpdateEveryColumnTest(TextGRPCServerUpdateFunc, Table1)