diff --git a/bin/templates/README.md b/bin/templates/README.md_ similarity index 87% rename from bin/templates/README.md rename to bin/templates/README.md_ index d1d4f07..7b5f6dd 100644 --- a/bin/templates/README.md +++ b/bin/templates/README.md_ @@ -19,22 +19,23 @@ from module "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/crud_starter" Also, to get started, the environment variables must be filled in: +(in ".env" file) 1) for DB CRUD: - DB_HOST="10.1.9.23" - DB_NAME="claim" - DB_SCHEME="public" - DB_PORT="5432" + DB_HOST="" + DB_NAME="" + DB_SCHEME="" + DB_PORT="" DB_USER="" DB_PASSWORD="" 2) for GRPC: - SYNC_SERVICE_HOST=10.1.9.150 - SYNC_SERVICE_PORT=30031 + SYNC_SERVICE_HOST= + SYNC_SERVICE_PORT= 3) for NRPC: - BUS_LOCAL_HOST="10.1.9.150" - BUS_LOCAL_PORT=30222 + BUS_LOCAL_HOST= + BUS_LOCAL_PORT= For NRPC (GRPC) it is advisable to connect there first and disconnect at the end nrpc_client.Connect() diff --git a/bin/templates/configs_/settings.txt b/bin/templates/configs_/settings.txt index 9f5855c..8b29e89 100644 --- a/bin/templates/configs_/settings.txt +++ b/bin/templates/configs_/settings.txt @@ -26,10 +26,10 @@ EXCLUDE_TABLES="ext_" #---------------------Template settings--------------------- #SERVICE_REPOSITORY_URL - URL of your new service repository (Github, gitlab, etc.) -SERVICE_REPOSITORY_URL="gitlab.aescorp.ru/dsp_dev/claim/sync_service" +SERVICE_REPOSITORY_URL="gitlab.aescorp.ru/dsp_dev/claim/crud_service" #SERVICE_NAME - service name for your new service -SERVICE_NAME=sync_service +SERVICE_NAME=crud_service #TEMPLATE_SERVICE_NAME - service name in your template files TEMPLATE_SERVICE_NAME=sync_service @@ -101,6 +101,9 @@ USE_DEFAULT_TEMPLATE=true #HAS_IS_DELETED - fill "true" if you have "is_deleted" column, and want Delete() Restore() functions. HAS_IS_DELETED=true +#TEMPLATE_EXTERNAL_PROTO_FILENAME - can fill real .proto file full filename with folder, from external real project - for use as template +TEMPLATE_EXTERNAL_PROTO_FILENAME=/home/user/GolandProjects/!sanek/sync_service/api/sync_service.proto + #---------------------Create files settings--------------------- #NEED_CREATE_CRUD - fill "true" if you want create crud operations files @@ -124,6 +127,9 @@ NEED_CREATE_DB_TEST=true #NEED_CREATE_DB - fill "true" if you want create DB .go files NEED_CREATE_DB=true +#NEED_CREATE_DB_TABLES - fill "true" if you want create DB .go files +NEED_CREATE_DB_TABLES=true + #NEED_CREATE_GRPC_SERVER_TEST - fill "true" if you want create GRPC server _test.go files NEED_CREATE_GRPC_SERVER_TEST=true @@ -230,4 +236,10 @@ TEMPLATES_GRPC_CLIENT_TABLES_CACHE_FILENAME="grpc_client_table_cache.go_" TEMPLATES_GRPC_CLIENT_TABLES_CACHE_TEST_FILENAME="grpc_client_table_cache_test.go_" #CACHE_ELEMENTS_COUNT_MAX - maximum elements counts in cache, for every table -CACHE_ELEMENTS_COUNT_MAX=1000 \ No newline at end of file +CACHE_ELEMENTS_COUNT_MAX=1000 + +#TEMPLATES_README_MD_FILENAME - short filename of "README.md_" file +TEMPLATES_README_MD_FILENAME="README.md_" + +#TEMPLATES_README_RUS_FILENAME - short filename of "readme.rus_" file +TEMPLATES_README_RUS_FILENAME="readme.rus_" diff --git a/bin/templates/pkg/db/calc_struct_version/calc_struct_version.go b/bin/templates/pkg/db/calc_struct_version/calc_struct_version.go index ea44705..ccf2bce 100644 --- a/bin/templates/pkg/db/calc_struct_version/calc_struct_version.go +++ b/bin/templates/pkg/db/calc_struct_version/calc_struct_version.go @@ -14,11 +14,16 @@ func CalcStructVersion(t reflect.Type) uint32 { // имя + тип поля s := "" for i := range names { - s = s + t.Field(i).Name - s = s + t.Field(i).Type.Name() + Field1 := t.Field(i) + s = s + Field1.Name + s = s + Field1.Type.Name() + if Field1.Anonymous == true && Field1.Type != t { + version2 := CalcStructVersion(Field1.Type) + ReturnVar = ReturnVar + version2 + } } - ReturnVar = micro.Hash(s) + ReturnVar = ReturnVar + micro.Hash(s) return ReturnVar } diff --git a/bin/templates/readme.rus b/bin/templates/readme.rus_ similarity index 99% rename from bin/templates/readme.rus rename to bin/templates/readme.rus_ index 32870aa..16e970d 100644 --- a/bin/templates/readme.rus +++ b/bin/templates/readme.rus_ @@ -19,6 +19,7 @@ InitCrudTransport_NRPC() "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/crud_starter" Также для начала работы должны быть заполнены переменные окружения: +(в файле .env) 1) для DB CRUD: DB_HOST="10.1.9.23" diff --git a/internal/config/config.go b/internal/config/config.go index 63ff6b6..60e1e91 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -54,6 +54,8 @@ type SettingsINI struct { TEMPLATES_GRPC_SERVER_TABLE_UPDATE_TEST_FILENAME string TEMPLATES_GRPC_CLIENT_TABLES_CACHE_FILENAME string TEMPLATES_GRPC_CLIENT_TABLES_CACHE_TEST_FILENAME string + TEMPLATES_README_MD_FILENAME string + TEMPLATES_README_RUS_FILENAME string NEED_CREATE_MODEL_STRUCT bool NEED_CREATE_MODEL_CRUD bool NEED_CREATE_DB bool @@ -490,6 +492,16 @@ func FillSettings() { } Settings.CACHE_ELEMENTS_COUNT_MAX = i + // + Name = "TEMPLATES_README_MD_FILENAME" + s = Getenv(Name, true) + Settings.TEMPLATES_README_MD_FILENAME = s + + // + Name = "TEMPLATES_README_RUS_FILENAME" + s = Getenv(Name, true) + Settings.TEMPLATES_README_RUS_FILENAME = s + } // CurrentDirectory - возвращает текущую директорию ОС diff --git a/internal/create_files/readme_file/readme_file.go b/internal/create_files/readme_file/readme_file.go new file mode 100644 index 0000000..ee1f1a9 --- /dev/null +++ b/internal/create_files/readme_file/readme_file.go @@ -0,0 +1,107 @@ +package readme_file + +import ( + "github.com/ManyakRus/crud_generator/internal/config" + "github.com/ManyakRus/crud_generator/internal/constants" + "github.com/ManyakRus/crud_generator/internal/create_files" + "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 = CreateReadmeMD() + if err != nil { + log.Error("CreateReadmeMD() error: ", err) + return err + } + + err = CreateReadmeRus() + if err != nil { + log.Error("CreateReadmeRus() error: ", err) + return err + } + + return err +} + +// CreateReadmeMD - создаёт 1 файл в корне проекта +func CreateReadmeMD() 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() + DirTemplatesReadmeFile := DirTemplates + DirReadyReadmeFile := DirReady + filename := create_files.DeleteLastUnderline(config.Settings.TEMPLATES_README_MD_FILENAME) + FilenameTemplateReadmeFile := DirTemplatesReadmeFile + config.Settings.TEMPLATES_README_MD_FILENAME + FilenameReadyReadmeFile := DirReadyReadmeFile + filename + + //создадим папку готовых файлов + folders.CreateFolder(DirReadyReadmeFile) + + bytes, err := os.ReadFile(FilenameTemplateReadmeFile) + if err != nil { + log.Panic("ReadFile() ", FilenameTemplateReadmeFile, " error: ", err) + } + TextReadmeFile := string(bytes) + + //заменим URL + CrudStarterURLOld := "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/crud_starter" + CrudStarterURL := create_files.FindCrudStarterURL() + TextReadmeFile = strings.ReplaceAll(TextReadmeFile, CrudStarterURLOld, CrudStarterURL) + + //запись файла + err = os.WriteFile(FilenameReadyReadmeFile, []byte(TextReadmeFile), constants.FILE_PERMISSIONS) + + return err +} + +// CreateReadmeRus - создаёт 1 файл в корне проекта +func CreateReadmeRus() 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() + DirTemplatesReadmeFile := DirTemplates + DirReadyReadmeFile := DirReady + filename := create_files.DeleteLastUnderline(config.Settings.TEMPLATES_README_RUS_FILENAME) + FilenameTemplateReadmeFile := DirTemplatesReadmeFile + config.Settings.TEMPLATES_README_RUS_FILENAME + FilenameReadyReadmeFile := DirReadyReadmeFile + filename + + //создадим папку готовых файлов + folders.CreateFolder(DirReadyReadmeFile) + + bytes, err := os.ReadFile(FilenameTemplateReadmeFile) + if err != nil { + log.Panic("ReadFile() ", FilenameTemplateReadmeFile, " error: ", err) + } + TextReadmeFile := string(bytes) + + //заменим URL + CrudStarterURLOld := "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/crud_starter" + CrudStarterURL := create_files.FindCrudStarterURL() + TextReadmeFile = strings.ReplaceAll(TextReadmeFile, CrudStarterURLOld, CrudStarterURL) + + //запись файла + err = os.WriteFile(FilenameReadyReadmeFile, []byte(TextReadmeFile), constants.FILE_PERMISSIONS) + + return err +} diff --git a/internal/create_files/readme_file/readme_file_test.go b/internal/create_files/readme_file/readme_file_test.go new file mode 100644 index 0000000..6f2eda3 --- /dev/null +++ b/internal/create_files/readme_file/readme_file_test.go @@ -0,0 +1 @@ +package readme_file diff --git a/internal/logic/logic.go b/internal/logic/logic.go index 501c601..9d05347 100644 --- a/internal/logic/logic.go +++ b/internal/logic/logic.go @@ -17,6 +17,7 @@ import ( "github.com/ManyakRus/crud_generator/internal/create_files/model_tables" "github.com/ManyakRus/crud_generator/internal/create_files/nrpc_client" "github.com/ManyakRus/crud_generator/internal/create_files/protobuf" + "github.com/ManyakRus/crud_generator/internal/create_files/readme_file" "github.com/ManyakRus/crud_generator/internal/create_files/server_grpc_func" "github.com/ManyakRus/crud_generator/internal/create_files/server_grpc_starter" "github.com/ManyakRus/crud_generator/internal/create_files/server_nrpc_starter" @@ -184,5 +185,12 @@ func StartFillAll() error { return err } + //readme + err = readme_file.CreateAllFiles() + if err != nil { + //log.Error("env_file.CreateAllFiles() error: ", err) + return err + } + return err }