1
0
mirror of https://github.com/ManyakRus/crud_generator.git synced 2024-12-22 00:36:41 +02:00

сделал TEMPLATES_GRPC_SERVER_TABLE_UPDATE_FILENAME

This commit is contained in:
Nikitin Aleksandr 2024-02-20 17:14:48 +03:00
parent 5321202424
commit 9f0ef9d535
7 changed files with 120 additions and 46 deletions

View File

@ -207,3 +207,10 @@ TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_FILENAME="grpc_client_table_update.go_"
#TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_TEST_FILENAME - short filename of "grpc_client_table_update_test.go_" file
TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_TEST_FILENAME="grpc_client_table_update_test.go_"
#TEMPLATES_GRPC_SERVER_TABLE_UPDATE_FILENAME - short filename of "server_grpc_table_update.go_" file
TEMPLATES_GRPC_SERVER_TABLE_UPDATE_FILENAME="server_grpc_table_update.go_"
#TEMPLATES_GRPC_SERVER_TABLE_UPDATE_TEST_FILENAME - short filename of "server_grpc_table_update_test.go_" file
TEMPLATES_GRPC_SERVER_TABLE_UPDATE_TEST_FILENAME="server_grpc_table_update_test.go_"

View File

@ -0,0 +1,8 @@
package server_grpc
import (
"context"
"github.com/ManyakRus/starter/micro"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/api/grpc_proto"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
)

View File

@ -0,0 +1,10 @@
package server_grpc
import (
"context"
"github.com/ManyakRus/starter/config_main"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/api/grpc_proto"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/crud_starter"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
"testing"
)

View File

@ -50,6 +50,8 @@ type SettingsINI struct {
TEMPLATES_CRUD_TABLE_UPDATE_TEST_FILENAME string
TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_FILENAME string
TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_TEST_FILENAME string
TEMPLATES_GRPC_SERVER_TABLE_UPDATE_FILENAME string
TEMPLATES_GRPC_SERVER_TABLE_UPDATE_TEST_FILENAME string
NEED_CREATE_MODEL_STRUCT bool
NEED_CREATE_MODEL_CRUD bool
NEED_CREATE_DB bool
@ -438,6 +440,15 @@ func FillSettings() {
s = Getenv(Name, true)
Settings.TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_TEST_FILENAME = s
//
Name = "TEMPLATES_GRPC_SERVER_TABLE_UPDATE_FILENAME"
s = Getenv(Name, true)
Settings.TEMPLATES_GRPC_SERVER_TABLE_UPDATE_FILENAME = s
//
Name = "TEMPLATES_GRPC_SERVER_TABLE_UPDATE_TEST_FILENAME"
s = Getenv(Name, true)
Settings.TEMPLATES_GRPC_SERVER_TABLE_UPDATE_TEST_FILENAME = s
}
// CurrentDirectory - возвращает текущую директорию ОС

View File

@ -516,6 +516,8 @@ func CreateFilesUpdateEveryColumn(Table1 *types.Table) error {
//заменим импорты
if config.Settings.USE_DEFAULT_TEMPLATE == true {
TextCrud = create_files.DeleteTemplateRepositoryImports(TextCrud)
DBConstantsURL := create_files.FindDBConstantsURL()
TextCrud = create_files.AddImport(TextCrud, DBConstantsURL)
@ -667,12 +669,14 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error {
//`
//заменим импорты
//if config.Settings.USE_DEFAULT_TEMPLATE == true {
if config.Settings.USE_DEFAULT_TEMPLATE == true {
TextCrud = create_files.DeleteTemplateRepositoryImports(TextCrud)
ModelTableURL := create_files.FindModelTableURL(TableName)
TextCrud = create_files.AddImport(TextCrud, ModelTableURL)
//TextCrud = create_files.ConvertIdToAlias(TextCrud, Table1)
//}
}
//создание текста
TextUpdateEveryColumn := FindTextUpdateEveryColumnTest(TextCrudUpdateFunc, Table1)

View File

@ -409,6 +409,8 @@ func CreateFilesUpdateEveryColumn(Table1 *types.Table) error {
//заменим импорты
if config.Settings.USE_DEFAULT_TEMPLATE == true {
TextGRPC_Client = create_files.DeleteTemplateRepositoryImports(TextGRPC_Client)
ProtoURL := create_files.FindProtoURL()
TextGRPC_Client = create_files.AddImport(TextGRPC_Client, ProtoURL)
@ -565,7 +567,9 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error {
//`
//заменим импорты
//if config.Settings.USE_DEFAULT_TEMPLATE == true {
if config.Settings.USE_DEFAULT_TEMPLATE == true {
TextGRPC_Client = create_files.DeleteTemplateRepositoryImports(TextGRPC_Client)
GRPCClientURL := create_files.FindGRPClientURL()
TextGRPC_Client = create_files.AddImport(TextGRPC_Client, GRPCClientURL)
@ -573,7 +577,7 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error {
TextGRPC_Client = create_files.AddImport(TextGRPC_Client, ModelTableURL)
//TextGRPC_Client = create_files.ConvertIdToAlias(TextGRPC_Client, Table1)
//}
}
//создание текста
TextUpdateEveryColumn := FindTextUpdateEveryColumnTest(TextGRPC_Client_UpdateFunc, Table1)

View File

@ -349,31 +349,46 @@ func CreateFilesUpdateEveryColumn(Table1 *types.Table) error {
DirTemplatesGRPCServer := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_GRPC_SERVER + micro.SeparatorFile()
DirReadyGRPCServer := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_SERVER + micro.SeparatorFile()
FilenameTemplateGRPCServer := DirTemplatesGRPCServer + constants.SERVER_GRPC_TABLE_UPDATE_FUNC_FILENAME
FilenameTemplateGRPCServerFunc := DirTemplatesGRPCServer + constants.SERVER_GRPC_TABLE_UPDATE_FUNC_FILENAME
TableName := strings.ToLower(Table1.Name)
DirReadyTable := DirReadyGRPCServer
FilenameReadyGRPCServerUpdate := DirReadyTable + config.Settings.PREFIX_SERVER_GRPC + TableName + "_update.go"
FilenameReadyGRPCServerUpdateFunc := DirReadyTable + config.Settings.PREFIX_SERVER_GRPC + TableName + "_update.go"
//создадим папку готовых файлов
folders.CreateFolder(DirReadyTable)
bytes, err := os.ReadFile(FilenameTemplateGRPCServer)
//читаем шаблон файла, только функции
bytes, err := os.ReadFile(FilenameTemplateGRPCServerFunc)
if err != nil {
log.Panic("ReadFile() ", FilenameTemplateGRPCServer, " error: ", err)
log.Panic("ReadFile() ", FilenameTemplateGRPCServerFunc, " error: ", err)
}
TextGRPCServerUpdateFunc := string(bytes)
PackageName := micro.LastWord(config.Settings.TEMPLATE_FOLDERNAME_GRPC_SERVER)
TextGRPCServer := "package " + PackageName + "\n\n"
TextGRPCServer = TextGRPCServer + `import (
"context"
"github.com/ManyakRus/starter/micro"
)
//читаем шаблон файла, без функций
FilenameTemplateGRPCServerUpdate := DirTemplatesGRPCServer + config.Settings.TEMPLATES_GRPC_SERVER_TABLE_UPDATE_FILENAME
bytes, err = os.ReadFile(FilenameTemplateGRPCServerUpdate)
if err != nil {
log.Panic("ReadFile() ", FilenameTemplateGRPCServerUpdate, " error: ", err)
}
TextGRPCServer := string(bytes)
TextGRPCServer = TextGRPCServer + "\n"
`
//заменим имя пакета на новое
TextGRPCServer = create_files.ReplacePackageName(TextGRPCServer, DirReadyTable)
// PackageName := micro.LastWord(config.Settings.TEMPLATE_FOLDERNAME_GRPC_SERVER)
// TextGRPCServer := "package " + PackageName + "\n\n"
// TextGRPCServer = TextGRPCServer + `import (
// "context"
// "github.com/ManyakRus/starter/micro"
//)
//
//`
//заменим импорты
if config.Settings.USE_DEFAULT_TEMPLATE == true {
TextGRPCServer = create_files.DeleteTemplateRepositoryImports(TextGRPCServer)
ModelTableURL := create_files.FindModelTableURL(TableName)
TextGRPCServer = create_files.AddImport(TextGRPCServer, ModelTableURL)
@ -410,7 +425,7 @@ func CreateFilesUpdateEveryColumn(Table1 *types.Table) error {
TextGRPCServer = create_files.DeleteEmptyLines(TextGRPCServer)
//запись файла
err = os.WriteFile(FilenameReadyGRPCServerUpdate, []byte(TextGRPCServer), constants.FILE_PERMISSIONS)
err = os.WriteFile(FilenameReadyGRPCServerUpdateFunc, []byte(TextGRPCServer), constants.FILE_PERMISSIONS)
return err
}
@ -478,7 +493,7 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error {
DirTemplatesGRPCServer := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_GRPC_SERVER + micro.SeparatorFile()
DirReadyGRPCServer := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_SERVER + micro.SeparatorFile()
FilenameTemplateGRPCServer := DirTemplatesGRPCServer + constants.SERVER_GRPC_TABLE_UPDATE_FUNC_TEST_FILENAME
FilenameTemplateGRPCServerFunc := DirTemplatesGRPCServer + constants.SERVER_GRPC_TABLE_UPDATE_FUNC_TEST_FILENAME
TableName := strings.ToLower(Table1.Name)
DirReadyTable := DirReadyGRPCServer
FilenameReadyGRPCServerUpdate := DirReadyTable + config.Settings.PREFIX_SERVER_GRPC + TableName + "_update_test.go"
@ -486,24 +501,39 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error {
//создадим папку готовых файлов
folders.CreateFolder(DirReadyTable)
bytes, err := os.ReadFile(FilenameTemplateGRPCServer)
//читаем шаблон файла, только функции
bytes, err := os.ReadFile(FilenameTemplateGRPCServerFunc)
if err != nil {
log.Panic("ReadFile() ", FilenameTemplateGRPCServer, " error: ", err)
log.Panic("ReadFile() ", FilenameTemplateGRPCServerFunc, " error: ", err)
}
TextGRPCServerUpdateFunc := string(bytes)
PackageName := micro.LastWord(config.Settings.TEMPLATE_FOLDERNAME_GRPC_SERVER)
TextGRPCServer := "package " + PackageName + "\n\n"
TextGRPCServer = TextGRPCServer + `import (
"context"
"testing"
"github.com/ManyakRus/starter/config_main"
)
//читаем шаблон файла, без функций
FilenameTemplateGRPCServerUpdate := DirTemplatesGRPCServer + config.Settings.TEMPLATES_GRPC_SERVER_TABLE_UPDATE_TEST_FILENAME
bytes, err = os.ReadFile(FilenameTemplateGRPCServerUpdate)
if err != nil {
log.Panic("ReadFile() ", FilenameTemplateGRPCServerUpdate, " error: ", err)
}
TextGRPCServer := string(bytes)
TextGRPCServer = TextGRPCServer + "\n"
`
//заменим имя пакета на новое
TextGRPCServer = create_files.ReplacePackageName(TextGRPCServer, DirReadyTable)
// PackageName := micro.LastWord(config.Settings.TEMPLATE_FOLDERNAME_GRPC_SERVER)
// TextGRPCServer := "package " + PackageName + "\n\n"
// TextGRPCServer = TextGRPCServer + `import (
// "context"
// "testing"
// "github.com/ManyakRus/starter/config_main"
//)
//
//`
//заменим импорты
//if config.Settings.USE_DEFAULT_TEMPLATE == true {
if config.Settings.USE_DEFAULT_TEMPLATE == true {
TextGRPCServer = create_files.DeleteTemplateRepositoryImports(TextGRPCServer)
ModelTableURL := create_files.FindModelTableURL(TableName)
TextGRPCServer = create_files.AddImport(TextGRPCServer, ModelTableURL)
@ -517,7 +547,7 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error {
TextGRPCServer = create_files.AddImport(TextGRPCServer, CrudStarterURL)
//TextGRPCServer = create_files.ConvertIdToAlias(TextGRPCServer, Table1)
//}
}
//создание текста
TextUpdateEveryColumn := FindTextUpdateEveryColumnTest(TextGRPCServerUpdateFunc, Table1)