1
0
mirror of https://github.com/ManyakRus/crud_generator.git synced 2025-01-03 01:22:21 +02:00

сделал api

This commit is contained in:
Nikitin Aleksandr 2023-11-29 15:56:40 +03:00
parent 634d316da3
commit 48302a229a
6 changed files with 56 additions and 21 deletions

View File

@ -5,8 +5,7 @@ FILEMAIN=./cmd/$(SERVICENAME)/main.go
FILEAPP=./bin/$(SERVICENAME)
NEW_REPO=$(SERVICENAME)
CD_GENERATION_PROTO=cd ./api
GENERATION_PROTO=generation_code.sh
GENERATION_PROTO=cd ./api && ./generation_code.sh
run:
@ -54,7 +53,6 @@ conn:
init:
clear
go mod init gitlab.aescorp.ru/dsp_dev/claim/sync_service
$(CD_GENERATION_PROTO)
$(GENERATION_PROTO)
go mod tidy
go mod vendor

View File

@ -91,7 +91,13 @@ func CreateENV() error {
Value = postgres_gorm.Settings.DB_PASSWORD
TextMakefile = ReplaceVariable(TextMakefile, VariableName, Value)
//запись файла
//запись файла в корень проекта
err = os.WriteFile(FilenameReadyENV, []byte(TextMakefile), constants.FILE_PERMISSIONS)
//запись файла в bin
Dir := DirReady + "bin" + micro.SeparatorFile()
folders.CreateFolder(Dir)
FilenameReadyENV = Dir + constants.ENV_FILENAME
err = os.WriteFile(FilenameReadyENV, []byte(TextMakefile), constants.FILE_PERMISSIONS)
return err

View File

@ -57,14 +57,14 @@ func CreateMakefile() error {
Value := config.Settings.SERVICE_REPOSITORY_URL
TextMakefile = ReplaceVariable(TextMakefile, VariableName, Value)
//заполним GENERATION_PROTO
VariableName = "CD_GENERATION_PROTO"
Value = "cd ./" + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + " && \\"
TextMakefile = ReplaceVariable(TextMakefile, VariableName, Value)
////заполним GENERATION_PROTO
//VariableName = "CD_GENERATION_PROTO"
//Value = "cd ./" + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + " && \\"
//TextMakefile = ReplaceVariable(TextMakefile, VariableName, Value)
//заполним GENERATION_PROTO
VariableName = "GENERATION_PROTO"
Value = "./" + constants.GENERATION_PROTO_FILENAME
Value = "cd ./" + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + " && " + "./" + constants.GENERATION_PROTO_FILENAME
TextMakefile = ReplaceVariable(TextMakefile, VariableName, Value)
//запись файла

View File

@ -53,18 +53,6 @@ func CreateServerGRPCStarter() error {
//заменим имя пакета на новое
create_files.ReplacePackageName(TextGRPCStarter, 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)
@ -73,6 +61,26 @@ func CreateServerGRPCStarter() error {
TextGRPCStarter = create_files.AddImport(TextGRPCStarter, ProtoURL)
}
//найдём текст после конца импортов
TextAfterImport := ""
pos1 := strings.Index(TextGRPCStarter, "\n)")
if pos1 >= 0 {
TextAfterImport = TextGRPCStarter[pos1+2:]
}
//заменим имя сервиса на новое
ServiceNameTemplate := config.Settings.TEMPLATE_SERVICE_NAME
ServiceName := config.Settings.SERVICE_NAME
TextAfterImport = strings.ReplaceAll(TextAfterImport, ServiceNameTemplate, ServiceName)
TextAfterImport = strings.ReplaceAll(TextAfterImport, micro.StringFromUpperCase(ServiceNameTemplate), micro.StringFromUpperCase(ServiceName))
//заменим имя сервиса на новое с CamelCase
ServiceNameTemplate = create_files.FormatName(ServiceNameTemplate)
ServiceName = create_files.FormatName(ServiceName)
TextAfterImport = strings.ReplaceAll(TextAfterImport, ServiceNameTemplate, ServiceName)
TextAfterImport = strings.ReplaceAll(TextAfterImport, micro.StringFromUpperCase(ServiceNameTemplate), micro.StringFromUpperCase(ServiceName))
TextGRPCStarter = TextGRPCStarter[:pos1+2] + TextAfterImport
//удаление пустого импорта
TextGRPCStarter = create_files.DeleteEmptyImport(TextGRPCStarter)

View File

@ -234,6 +234,10 @@ func DeleteFolder(FilenameFull string) error {
func CopyAllFiles_Exclude_(src, dest string) error {
var err error
//создадим папку готовых файлов
CreateFolder(dest)
//скопируем все файлы
opt := copy_files.Options{
Skip: CopyFilesFilterGo,
}

View File

@ -38,6 +38,7 @@ func StartFillAll() error {
}
if len(MapAll) == 0 {
log.Error("FillMapTable()error: len(MapAll) == 0")
return err
}
@ -45,108 +46,126 @@ func StartFillAll() error {
dir := micro.ProgramDir_bin()
err = folders.CopyAllFiles_Exclude_(dir+config.Settings.TEMPLATE_FOLDERNAME, dir+config.Settings.READY_FOLDERNAME)
if err != nil {
//log.Error("folders.CopyAllFiles_Exclude_() error: ", err)
return err
}
//модель
err = model.CreateAllFiles(MapAll)
if err != nil {
//log.Error("model.CreateAllFiles() error: ", err)
return err
}
//db crud
err = db_crud_tables.CreateAllFiles(MapAll)
if err != nil {
//log.Error("db_crud_tables.CreateAllFiles() error: ", err)
return err
}
//grpc_server
err = grpc_server.CreateAllFiles(MapAll)
if err != nil {
//log.Error("grpc_server.CreateAllFiles() error: ", err)
return err
}
//grpc_client tables
err = grpc_client_tables.CreateAllFiles(MapAll)
if err != nil {
//log.Error("grpc_client_tables.CreateAllFiles() error: ", err)
return err
}
//grpc_client
err = grpc_client.CreateAllFiles()
if err != nil {
//log.Error("grpc_client.CreateAllFiles() error: ", err)
return err
}
//nrpc_client
err = nrpc_client.CreateAllFiles()
if err != nil {
//log.Error("nrpc_client.CreateAllFiles() error: ", err)
return err
}
//grpc_client
err = nrpc_client_tables.CreateAllFiles(MapAll)
if err != nil {
//log.Error("nrpc_client_tables.CreateAllFiles() error: ", err)
return err
}
//grpc_proto
err = protobuf.CreateAllFiles(MapAll)
if err != nil {
//log.Error("protobuf.CreateAllFiles() error: ", err)
return err
}
//crud_starter
err = crud_starter.CreateAllFiles(MapAll)
if err != nil {
//log.Error("crud_starter.CreateAllFiles() error: ", err)
return err
}
//main file
err = main_file.CreateAllFiles()
if err != nil {
//log.Error("main_file.CreateAllFiles() error: ", err)
return err
}
//server_grpc_starter
err = server_grpc_starter.CreateAllFiles()
if err != nil {
//log.Error("server_grpc_starter.CreateAllFiles() error: ", err)
return err
}
//server_nrpc_starter
err = server_nrpc_starter.CreateAllFiles()
if err != nil {
//log.Error("server_nrpc_starter.CreateAllFiles() error: ", err)
return err
}
//server_grpc_func
err = server_grpc_func.CreateAllFiles()
if err != nil {
//log.Error("server_grpc_func.CreateAllFiles() error: ", err)
return err
}
//makefile
err = makefile.CreateAllFiles()
if err != nil {
//log.Error("makefile.CreateAllFiles() error: ", err)
return err
}
//generation_code.sh
err = generation_code_sh.CreateAllFiles()
if err != nil {
//log.Error("generation_code_sh.CreateAllFiles() error: ", err)
return err
}
//tables
err = db_tables.CreateAllFiles(MapAll)
if err != nil {
//log.Error("db_tables.CreateAllFiles() error: ", err)
return err
}
//env
err = env_file.CreateAllFiles()
if err != nil {
//log.Error("env_file.CreateAllFiles() error: ", err)
return err
}