mirror of
https://github.com/ManyakRus/crud_generator.git
synced 2025-01-04 13:23:00 +02:00
сделал grpc_client_func.go
This commit is contained in:
parent
f5941fe82c
commit
128c4458ec
@ -74,6 +74,12 @@ TEMPLATE_FOLDERNAME_GRPC_CLIENT="pkg/network/grpc/grpc_client"
|
||||
#TEMPLATE_FOLDERNAME_GRPC_CLIENT_FUNC - folder name for create "grpc_client_func.go" files
|
||||
TEMPLATE_FOLDERNAME_GRPC_CLIENT_FUNC="pkg/network/grpc/grpc_client_func"
|
||||
|
||||
#TEMPLATE_GRPC_CLIENT_FUNC_FILENAME - file name for create "grpc_client_func.go" files
|
||||
TEMPLATE_GRPC_CLIENT_FUNC_FILENAME="grpc_client_func.go_"
|
||||
|
||||
#TEMPLATE_GRPC_CLIENT_FUNC_TEST_FILENAME - file name for create "grpc_client_func_test.go" files
|
||||
TEMPLATE_GRPC_CLIENT_FUNC_TEST_FILENAME="grpc_client_func_test.go_"
|
||||
|
||||
|
||||
|
||||
#TEMPLATE_FOLDERNAME_NRPC_SERVER - folder name for create nrpc server files
|
||||
|
@ -55,6 +55,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
|
||||
TEMPLATE_GRPC_CLIENT_FUNC_FILENAME string
|
||||
TEMPLATE_GRPC_CLIENT_FUNC_TEST_FILENAME string
|
||||
TEMPLATES_README_MD_FILENAME string
|
||||
TEMPLATES_README_RUS_FILENAME string
|
||||
TEMPLATE_FOLDERNAME_CONSTANTS string
|
||||
@ -526,6 +528,16 @@ func FillSettings() {
|
||||
s = Getenv(Name, true)
|
||||
Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT_FUNC = s
|
||||
|
||||
//
|
||||
Name = "TEMPLATE_GRPC_CLIENT_FUNC_FILENAME"
|
||||
s = Getenv(Name, true)
|
||||
Settings.TEMPLATE_GRPC_CLIENT_FUNC_FILENAME = s
|
||||
|
||||
//
|
||||
Name = "TEMPLATE_GRPC_CLIENT_FUNC_TEST_FILENAME"
|
||||
s = Getenv(Name, true)
|
||||
Settings.TEMPLATE_GRPC_CLIENT_FUNC_TEST_FILENAME = s
|
||||
|
||||
}
|
||||
|
||||
// CurrentDirectory - возвращает текущую директорию ОС
|
||||
|
143
internal/create_files/grpc_client_func/grpc_client_func.go
Normal file
143
internal/create_files/grpc_client_func/grpc_client_func.go
Normal file
@ -0,0 +1,143 @@
|
||||
package grpc_client_func
|
||||
|
||||
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 - создаёт все файлы в папке grpc proto
|
||||
func CreateAllFiles() error {
|
||||
var err error
|
||||
|
||||
err = CreateFileGRPCClientFunc()
|
||||
if err != nil {
|
||||
log.Error("CreateFileGRPCClientFunc() error: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
err = CreateFileGRPCClientFuncTest()
|
||||
if err != nil {
|
||||
log.Error("CreateFileGRPCClientFuncTest() error: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// CreateFileGRPCClientFunc - создаёт 1 файл в папке grpc_client_func
|
||||
func CreateFileGRPCClientFunc() error {
|
||||
var err error
|
||||
|
||||
//чтение файлов
|
||||
DirBin := micro.ProgramDir_bin()
|
||||
DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile()
|
||||
DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile()
|
||||
DirTemplatesGRPCClientFunc := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT_FUNC + micro.SeparatorFile()
|
||||
DirReadyGRPCClientFunc := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT_FUNC + micro.SeparatorFile()
|
||||
FilenameReadyGRPCClientFunc := DirReadyGRPCClientFunc + config.Settings.TEMPLATE_GRPC_CLIENT_FUNC_FILENAME
|
||||
FilenameReadyGRPCClientFunc = create_files.DeleteLastUnderline(FilenameReadyGRPCClientFunc)
|
||||
FilenameTemplateGRPCClientFunc := DirTemplatesGRPCClientFunc + config.Settings.TEMPLATE_GRPC_CLIENT_FUNC_FILENAME
|
||||
|
||||
ok, err := micro.FileExists(FilenameTemplateGRPCClientFunc)
|
||||
if err != nil {
|
||||
log.Panic("FileExists() ", FilenameTemplateGRPCClientFunc, " error: ", err)
|
||||
}
|
||||
if ok == false {
|
||||
log.Debug("FileExists() ", FilenameTemplateGRPCClientFunc, " = false")
|
||||
return err
|
||||
}
|
||||
|
||||
//создадим папку готовых файлов
|
||||
folders.CreateFolder(DirReadyGRPCClientFunc)
|
||||
|
||||
bytes, err := os.ReadFile(FilenameTemplateGRPCClientFunc)
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateGRPCClientFunc, " error: ", err)
|
||||
}
|
||||
TextGRPCClientFunc := string(bytes)
|
||||
|
||||
//заменим название сервиса
|
||||
ServiceNameTemplate := config.Settings.TEMPLATE_SERVICE_NAME
|
||||
ServiceNameNew := config.Settings.SERVICE_NAME
|
||||
TextGRPCClientFunc = strings.ReplaceAll(TextGRPCClientFunc, ServiceNameTemplate, ServiceNameNew)
|
||||
|
||||
//добавим импорты
|
||||
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
TextGRPCClientFunc = create_files.DeleteTemplateRepositoryImports(TextGRPCClientFunc)
|
||||
|
||||
//
|
||||
ProtoURL := create_files.FindProtoURL()
|
||||
TextGRPCClientFunc = create_files.AddImport(TextGRPCClientFunc, ProtoURL)
|
||||
|
||||
//
|
||||
DBConstantsURL := create_files.FindDBConstantsURL()
|
||||
TextGRPCClientFunc = create_files.AddImport(TextGRPCClientFunc, DBConstantsURL)
|
||||
|
||||
//
|
||||
GRPCConstantsURL := create_files.FindGRPCConstantsURL()
|
||||
TextGRPCClientFunc = create_files.AddImport(TextGRPCClientFunc, GRPCConstantsURL)
|
||||
|
||||
}
|
||||
//запись файла
|
||||
err = os.WriteFile(FilenameReadyGRPCClientFunc, []byte(TextGRPCClientFunc), constants.FILE_PERMISSIONS)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// CreateFileGRPCClientFuncTest - создаёт 1 файл в папке grpc_client_func
|
||||
func CreateFileGRPCClientFuncTest() error {
|
||||
var err error
|
||||
|
||||
//чтение файлов
|
||||
DirBin := micro.ProgramDir_bin()
|
||||
DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile()
|
||||
DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile()
|
||||
DirTemplatesGRPCClientFunc := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT_FUNC + micro.SeparatorFile()
|
||||
DirReadyGRPCClientFunc := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT_FUNC + micro.SeparatorFile()
|
||||
FilenameReadyGRPCClientFunc := DirReadyGRPCClientFunc + config.Settings.TEMPLATE_GRPC_CLIENT_FUNC_TEST_FILENAME
|
||||
FilenameReadyGRPCClientFunc = create_files.DeleteLastUnderline(FilenameReadyGRPCClientFunc)
|
||||
FilenameTemplateGRPCClientFunc := DirTemplatesGRPCClientFunc + config.Settings.TEMPLATE_GRPC_CLIENT_FUNC_TEST_FILENAME
|
||||
|
||||
ok, err := micro.FileExists(FilenameTemplateGRPCClientFunc)
|
||||
if err != nil {
|
||||
log.Panic("FileExists() ", FilenameTemplateGRPCClientFunc, " error: ", err)
|
||||
}
|
||||
if ok == false {
|
||||
log.Debug("FileExists() ", FilenameTemplateGRPCClientFunc, " = false")
|
||||
return err
|
||||
}
|
||||
|
||||
//создадим папку готовых файлов
|
||||
folders.CreateFolder(DirReadyGRPCClientFunc)
|
||||
|
||||
bytes, err := os.ReadFile(FilenameTemplateGRPCClientFunc)
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateGRPCClientFunc, " error: ", err)
|
||||
}
|
||||
TextGRPCClientFunc := string(bytes)
|
||||
|
||||
//заменим название сервиса
|
||||
ServiceNameTemplate := config.Settings.TEMPLATE_SERVICE_NAME
|
||||
ServiceNameNew := config.Settings.SERVICE_NAME
|
||||
TextGRPCClientFunc = strings.ReplaceAll(TextGRPCClientFunc, ServiceNameTemplate, ServiceNameNew)
|
||||
|
||||
//добавим импорты
|
||||
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
TextGRPCClientFunc = create_files.DeleteTemplateRepositoryImports(TextGRPCClientFunc)
|
||||
|
||||
//
|
||||
DBConstantsURL := create_files.FindDBConstantsURL()
|
||||
TextGRPCClientFunc = create_files.AddImport(TextGRPCClientFunc, DBConstantsURL)
|
||||
|
||||
}
|
||||
//запись файла
|
||||
err = os.WriteFile(FilenameReadyGRPCClientFunc, []byte(TextGRPCClientFunc), constants.FILE_PERMISSIONS)
|
||||
|
||||
return err
|
||||
}
|
@ -0,0 +1 @@
|
||||
package grpc_client_func
|
@ -11,6 +11,7 @@ import (
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/env_file"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/generation_code_sh"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/grpc_client"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/grpc_client_func"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/grpc_client_tables"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/main_file"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/makefile"
|
||||
@ -200,5 +201,12 @@ func StartFillAll() error {
|
||||
return err
|
||||
}
|
||||
|
||||
//grpc_client_func
|
||||
err = grpc_client_func.CreateAllFiles()
|
||||
if err != nil {
|
||||
//log.Error("env_file.CreateAllFiles() error: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user