diff --git a/bin/templates/pkg/object_model/entities/model_crud.go_ b/bin/templates/pkg/object_model/entities/model_crud.go_ index a8008fb..fb563b4 100644 --- a/bin/templates/pkg/object_model/entities/model_crud.go_ +++ b/bin/templates/pkg/object_model/entities/model_crud.go_ @@ -3,7 +3,7 @@ package lawsuit_status_types import ( "encoding/json" "github.com/vmihailenco/msgpack/v5" - "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/functions/calc_struct_version" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/calc_struct_version" "reflect" ) diff --git a/internal/config/config.go b/internal/config/config.go index 8812f14..52a67be 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -15,6 +15,7 @@ type SettingsINI struct { EXCLUDE_TABLES string TEMPLATE_FOLDERNAME string TEMPLATE_FOLDERNAME_MODEL string + TEMPLATE_FOLDERNAME_DB string TEMPLATE_FOLDERNAME_CRUD string TEMPLATE_FOLDERNAME_TABLES string TEMPLATE_FOLDERNAME_GRPC string @@ -148,6 +149,7 @@ func FillSettings() { Settings.PREFIX_TABLE = os.Getenv("PREFIX_TABLE") Settings.TEMPLATE_FOLDERNAME_TABLES = os.Getenv("TEMPLATE_FOLDERNAME_TABLES") Settings.PREFIX_MODEL = os.Getenv("PREFIX_MODEL") + Settings.TEMPLATE_FOLDERNAME_DB = os.Getenv("TEMPLATE_FOLDERNAME_DB") } diff --git a/internal/create_files/create_files.go b/internal/create_files/create_files.go index 93bca7f..a961b65 100644 --- a/internal/create_files/create_files.go +++ b/internal/create_files/create_files.go @@ -261,8 +261,8 @@ func FindModelURL() string { return Otvet } -// FindGRPCServerlURL - возвращает URL репозитория с пакетом "server_grpc" -func FindGRPCServerlURL() string { +// FindGRPCServerURL - возвращает URL репозитория с пакетом "server_grpc" +func FindGRPCServerURL() string { Otvet := "" Otvet = config.Settings.SERVICE_REPOSITORY_URL + "/" + config.Settings.TEMPLATE_FOLDERNAME_GRPC_SERVER @@ -342,6 +342,42 @@ func FindModelTableURL(TableName string) string { return Otvet } +// FindNRPCClientURL - возвращает URL репозитория с пакетом "nrpc_client" +func FindNRPCClientURL() string { + Otvet := "" + + Otvet = config.Settings.SERVICE_REPOSITORY_URL + "/" + config.Settings.TEMPLATE_FOLDERNAME_NRPC_CLIENT + + return Otvet +} + +// FindDBConstantsURL - возвращает URL репозитория с пакетом db "constants" +func FindDBConstantsURL() string { + Otvet := "" + + Otvet = config.Settings.SERVICE_REPOSITORY_URL + "/" + config.Settings.TEMPLATE_FOLDERNAME_DB + "/" + "constants" + + return Otvet +} + +// FindCrudStarterURL - возвращает URL репозитория с пакетом "crud_starter" +func FindCrudStarterURL() string { + Otvet := "" + + Otvet = config.Settings.SERVICE_REPOSITORY_URL + "/" + config.Settings.TEMPLATE_FOLDERNAME_CRUD_STARTER + + return Otvet +} + +// FindCalcStructVersionURL - возвращает URL репозитория с пакетом "calc_struct_version" +func FindCalcStructVersionURL() string { + Otvet := "" + + Otvet = config.Settings.SERVICE_REPOSITORY_URL + "/" + config.Settings.TEMPLATE_FOLDERNAME_DB + "/" + "calc_struct_version" + + return Otvet +} + func FindTextDefaultValue(Column1 *types.Column) string { var Otvet string diff --git a/internal/create_files/db_crud/db_crud.go b/internal/create_files/db_crud/db_crud.go index f60e859..22063ae 100644 --- a/internal/create_files/db_crud/db_crud.go +++ b/internal/create_files/db_crud/db_crud.go @@ -58,15 +58,15 @@ func CreateFiles(Table1 *types.Table) error { FilenameTemplateDB := DirTemplatesDB + constants.TemplateFilenameCrudGo TableName := strings.ToLower(Table1.Name) - DirTable := DirReadyDB + config.Settings.PREFIX_CRUD + TableName - FilenameReadyDB := DirTable + micro.SeparatorFile() + config.Settings.PREFIX_CRUD + TableName + ".go" + DirReadyTable := DirReadyDB + config.Settings.PREFIX_CRUD + TableName + FilenameReadyDB := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_CRUD + TableName + ".go" //создадим каталог - ok, err := micro.FileExists(DirTable) + ok, err := micro.FileExists(DirReadyTable) if ok == false { - err = os.MkdirAll(DirTable, 0777) + err = os.MkdirAll(DirReadyTable, 0777) if err != nil { - log.Panic("Mkdir() ", DirTable, " error: ", err) + log.Panic("Mkdir() ", DirReadyTable, " error: ", err) } } @@ -77,7 +77,17 @@ func CreateFiles(Table1 *types.Table) error { TextDB := string(bytes) //заменим имя пакета на новое - create_files.ReplacePackageName(TextDB, DirTable) + create_files.ReplacePackageName(TextDB, DirReadyTable) + + //заменим импорты + if config.Settings.USE_DEFAULT_TEMPLATE == true { + TextDB = create_files.DeleteTemplateRepositoryImports(TextDB) + + TextDB = create_files.AddImport(TextDB, DirReadyTable) + + ConstantsURL := create_files.FindGRPCConstantsURL() + TextDB = create_files.AddImport(TextDB, ConstantsURL) + } //создание текста ModelName := Table1.NameGo @@ -121,15 +131,15 @@ func CreateTestFiles(Table1 *types.Table) error { DirReadyDB := DirReady + config.Settings.TEMPLATE_FOLDERNAME_CRUD + micro.SeparatorFile() FilenameTemplateDB := DirTemplatesDB + constants.TemplateFilenameCrudGoTest - DirTable := DirReadyDB + config.Settings.PREFIX_CRUD + TableName - FilenameReadyDB := DirTable + micro.SeparatorFile() + config.Settings.PREFIX_CRUD + TableName + "_test.go" + DirReadyTable := DirReadyDB + config.Settings.PREFIX_CRUD + TableName + FilenameReadyDB := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_CRUD + TableName + "_test.go" //создадим каталог - ok, err := micro.FileExists(DirTable) + ok, err := micro.FileExists(DirReadyTable) if ok == false { - err = os.Mkdir(DirTable, 0777) + err = os.Mkdir(DirReadyTable, 0777) if err != nil { - log.Panic("Mkdir() ", DirTable, " error: ", err) + log.Panic("Mkdir() ", DirReadyTable, " error: ", err) } } @@ -140,7 +150,17 @@ func CreateTestFiles(Table1 *types.Table) error { TextDB := string(bytes) //заменим имя пакета на новое - create_files.ReplacePackageName(TextDB, DirTable) + create_files.ReplacePackageName(TextDB, DirReadyTable) + + //заменим импорты + if config.Settings.USE_DEFAULT_TEMPLATE == true { + TextDB = create_files.DeleteTemplateRepositoryImports(TextDB) + + TextDB = create_files.AddImport(TextDB, DirReadyTable) + + ConstantsURL := create_files.FindGRPCConstantsURL() + TextDB = create_files.AddImport(TextDB, ConstantsURL) + } //создание текста ModelName := Table1.NameGo 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 dc94baf..aec4dde 100644 --- a/internal/create_files/grpc_client_tables/grpc_client_tables.go +++ b/internal/create_files/grpc_client_tables/grpc_client_tables.go @@ -77,6 +77,17 @@ func CreateFiles(Table1 *types.Table) error { //заменим имя пакета на новое create_files.ReplacePackageName(TextGRPCClient, DirReadyTable) + //заменим импорты + if config.Settings.USE_DEFAULT_TEMPLATE == true { + TextGRPCClient = create_files.DeleteTemplateRepositoryImports(TextGRPCClient) + + ConstantsURL := create_files.FindGRPCConstantsURL() + TextGRPCClient = create_files.AddImport(TextGRPCClient, ConstantsURL) + + ProtoURL := create_files.FindProtoURL() + TextGRPCClient = create_files.AddImport(TextGRPCClient, ProtoURL) + } + //создание текста ModelName := Table1.NameGo TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) @@ -155,6 +166,14 @@ func CreateTestFiles(Table1 *types.Table) error { //заменим имя пакета на новое create_files.ReplacePackageName(TextGRPCClient, DirReadyTable) + //заменим импорты + if config.Settings.USE_DEFAULT_TEMPLATE == true { + TextGRPCClient = create_files.DeleteTemplateRepositoryImports(TextGRPCClient) + + ConstantsURL := create_files.FindGRPCConstantsURL() + TextGRPCClient = create_files.AddImport(TextGRPCClient, ConstantsURL) + } + //создание текста ModelName := Table1.NameGo TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) diff --git a/internal/create_files/grpc_server/grpc_server.go b/internal/create_files/grpc_server/grpc_server.go index 7ffc6ce..4b8324a 100644 --- a/internal/create_files/grpc_server/grpc_server.go +++ b/internal/create_files/grpc_server/grpc_server.go @@ -67,6 +67,17 @@ func CreateFiles(Table1 *types.Table) error { //заменим имя пакета на новое create_files.ReplacePackageName(TextGRPCServer, DirReadyTable) + //заменим импорты + if config.Settings.USE_DEFAULT_TEMPLATE == true { + TextGRPCServer = create_files.DeleteTemplateRepositoryImports(TextGRPCServer) + + ModelTableURL := create_files.FindModelTableURL(TableName) + TextGRPCServer = create_files.AddImport(TextGRPCServer, ModelTableURL) + + ProtoURL := create_files.FindProtoURL() + TextGRPCServer = create_files.AddImport(TextGRPCServer, ProtoURL) + } + //создание текста ModelName := Table1.NameGo TextGRPCServer = strings.ReplaceAll(TextGRPCServer, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) @@ -127,6 +138,20 @@ func CreateTestFiles(Table1 *types.Table) error { //заменим имя пакета на новое create_files.ReplacePackageName(TextGRPCServer, DirReadyTable) + //заменим импорты + if config.Settings.USE_DEFAULT_TEMPLATE == true { + TextGRPCServer = create_files.DeleteTemplateRepositoryImports(TextGRPCServer) + + ModelTableURL := create_files.FindModelTableURL(TableName) + TextGRPCServer = create_files.AddImport(TextGRPCServer, ModelTableURL) + + ProtoURL := create_files.FindProtoURL() + TextGRPCServer = create_files.AddImport(TextGRPCServer, ProtoURL) + + CrudStarterURL := create_files.FindCrudStarterURL() + TextGRPCServer = create_files.AddImport(TextGRPCServer, CrudStarterURL) + } + //создание текста ModelName := Table1.NameGo TextGRPCServer = strings.ReplaceAll(TextGRPCServer, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) diff --git a/internal/create_files/main_file/main_file.go b/internal/create_files/main_file/main_file.go index fccd9eb..df1d5ff 100644 --- a/internal/create_files/main_file/main_file.go +++ b/internal/create_files/main_file/main_file.go @@ -49,7 +49,7 @@ func CreateFileMain() error { if config.Settings.USE_DEFAULT_TEMPLATE == true { //GRPC if config.Settings.NEED_CREATE_GRPC == true { - TextImport := create_files.FindGRPCServerlURL() + TextImport := create_files.FindGRPCServerURL() TextMain = create_files.AddImport(TextMain, TextImport) } else { TextMain = strings.ReplaceAll(TextMain, "\n\tserver_grpc.Start()", "") diff --git a/internal/create_files/model/model.go b/internal/create_files/model/model.go index 229e469..26087de 100644 --- a/internal/create_files/model/model.go +++ b/internal/create_files/model/model.go @@ -90,6 +90,14 @@ func CreateFilesModel_struct(Table1 *types.Table, DirTemplatesModel, DirReadyMod //заменим имя пакета на новое create_files.ReplacePackageName(TextModel, DirReadyModel) + //заменим импорты + if config.Settings.USE_DEFAULT_TEMPLATE == true { + TextModel = create_files.DeleteTemplateRepositoryImports(TextModel) + + TableURL := create_files.FindTableNameURL(TableName) + TextModel = create_files.AddImport(TextModel, TableURL) + } + //создание текста //TextModel, TextModelStruct, ModelName, err := FindTextModelStruct(TextModel, Table1) //TextModel = ReplaceModelStruct(TextModel, TextModelStruct) @@ -151,6 +159,14 @@ func CreateFilesModel_crud(Table1 *types.Table, DirTemplatesModel, DirReadyModel //заменим имя пакета на новое create_files.ReplacePackageName(TextModel, DirReadyModel) + //заменим импорты + if config.Settings.USE_DEFAULT_TEMPLATE == true { + TextModel = create_files.DeleteTemplateRepositoryImports(TextModel) + + TableURL := create_files.FindCalcStructVersionURL() + TextModel = create_files.AddImport(TextModel, TableURL) + } + //создание текста TextModel = strings.ReplaceAll(TextModel, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) TextModel = strings.ReplaceAll(TextModel, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) diff --git a/internal/create_files/nrpc_client/nrpc_client.go b/internal/create_files/nrpc_client/nrpc_client.go index 6071ac2..8ddec29 100644 --- a/internal/create_files/nrpc_client/nrpc_client.go +++ b/internal/create_files/nrpc_client/nrpc_client.go @@ -76,6 +76,23 @@ func CreateFiles(Table1 *types.Table) error { //заменим имя пакета на новое create_files.ReplacePackageName(TextNRPCClient, DirReadyTable) + //заменим импорты + if config.Settings.USE_DEFAULT_TEMPLATE == true { + TextNRPCClient = create_files.DeleteTemplateRepositoryImports(TextNRPCClient) + + GRPCProtoURL := create_files.FindGRPCProtoURL() + TextNRPCClient = create_files.AddImport(TextNRPCClient, GRPCProtoURL) + + NRPCClientURL := create_files.FindNRPCClientURL() + TextNRPCClient = create_files.AddImport(TextNRPCClient, NRPCClientURL) + + GRPCConstantsURL := create_files.FindGRPCConstantsURL() + TextNRPCClient = create_files.AddImport(TextNRPCClient, GRPCConstantsURL) + + TableURL := create_files.FindModelTableURL(TableName) + TextNRPCClient = create_files.AddImport(TextNRPCClient, TableURL) + } + //создание текста ModelName := Table1.NameGo TextNRPCClient = strings.ReplaceAll(TextNRPCClient, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) @@ -133,6 +150,17 @@ func CreateTestFiles(Table1 *types.Table) error { //заменим имя пакета на новое create_files.ReplacePackageName(TextNRPCClient, DirReadyTable) + //заменим импорты + if config.Settings.USE_DEFAULT_TEMPLATE == true { + TextNRPCClient = create_files.DeleteTemplateRepositoryImports(TextNRPCClient) + + NRPCClientURL := create_files.FindNRPCClientURL() + TextNRPCClient = create_files.AddImport(TextNRPCClient, NRPCClientURL) + + TableURL := create_files.FindModelTableURL(TableName) + TextNRPCClient = create_files.AddImport(TextNRPCClient, TableURL) + } + //создание текста ModelName := Table1.NameGo TextNRPCClient = strings.ReplaceAll(TextNRPCClient, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) 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 7218be7..50942df 100644 --- a/internal/create_files/server_grpc_starter/server_grpc_starter.go +++ b/internal/create_files/server_grpc_starter/server_grpc_starter.go @@ -53,22 +53,22 @@ func CreateServerGRPCStarter() error { //создадим папку ready folders.CreateFolder(DirReadyServerGRPC) + //заменим имя сервиса на новое + ServiceNameTemplate := config.Settings.TEMPLATE_SERVICE_NAME + ServiceName := config.Settings.SERVICE_NAME + TextGRPCStarter = strings.ReplaceAll(TextGRPCStarter, ServiceNameTemplate, ServiceName) + TextGRPCStarter = strings.ReplaceAll(TextGRPCStarter, micro.StringFromUpperCase(ServiceNameTemplate), micro.StringFromUpperCase(ServiceName)) + + //заменим имя сервиса на новое с CamelCase + ServiceNameTemplate = create_files.FormatName(ServiceNameTemplate) + ServiceName = create_files.FormatName(ServiceName) + TextGRPCStarter = strings.ReplaceAll(TextGRPCStarter, ServiceNameTemplate, ServiceName) + TextGRPCStarter = strings.ReplaceAll(TextGRPCStarter, micro.StringFromUpperCase(ServiceNameTemplate), micro.StringFromUpperCase(ServiceName)) + + //добавим импорты if config.Settings.USE_DEFAULT_TEMPLATE == true { TextGRPCStarter = create_files.DeleteTemplateRepositoryImports(TextGRPCStarter) - //заменим имя сервиса на новое - ServiceNameTemplate := config.Settings.TEMPLATE_SERVICE_NAME - ServiceName := config.Settings.SERVICE_NAME - TextGRPCStarter = strings.ReplaceAll(TextGRPCStarter, ServiceNameTemplate, ServiceName) - TextGRPCStarter = strings.ReplaceAll(TextGRPCStarter, micro.StringFromUpperCase(ServiceNameTemplate), micro.StringFromUpperCase(ServiceName)) - - //заменим имя сервиса на новое с CamelCase - ServiceNameTemplate = create_files.FormatName(ServiceNameTemplate) - ServiceName = create_files.FormatName(ServiceName) - TextGRPCStarter = strings.ReplaceAll(TextGRPCStarter, ServiceNameTemplate, ServiceName) - TextGRPCStarter = strings.ReplaceAll(TextGRPCStarter, micro.StringFromUpperCase(ServiceNameTemplate), micro.StringFromUpperCase(ServiceName)) - - //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 2d43a43..6734161 100644 --- a/internal/create_files/server_nrpc_starter/server_nrpc_starter.go +++ b/internal/create_files/server_nrpc_starter/server_nrpc_starter.go @@ -53,26 +53,14 @@ func CreateServerGRPCStarter() error { folders.CreateFolder(DirReadyServerNRPC) 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)) - TextNRPCStarter = create_files.DeleteTemplateRepositoryImports(TextNRPCStarter) - //ProtoURL := create_files.FindProtoURL() + "/grpc_proto" - //TextNRPCStarter = create_files.AddImport(TextNRPCStarter, ProtoURL) - // - //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() + RepositoryServerGRPCURL := create_files.FindGRPCServerURL() TextNRPCStarter = create_files.AddImport(TextNRPCStarter, RepositoryServerGRPCURL) }