1
0
mirror of https://github.com/ManyakRus/crud_generator.git synced 2024-11-24 08:22:42 +02:00

сделал README.md_

This commit is contained in:
Nikitin Aleksandr 2024-04-04 15:18:28 +03:00
parent c40d220acd
commit 6e45a58664
8 changed files with 161 additions and 14 deletions

View File

@ -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()

View File

@ -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
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_"

View File

@ -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
}

View File

@ -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"

View File

@ -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 - возвращает текущую директорию ОС

View File

@ -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
}

View File

@ -0,0 +1 @@
package readme_file

View File

@ -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
}