mirror of
https://github.com/ManyakRus/crud_generator.git
synced 2024-12-22 00:36:41 +02:00
сделал TEMPLATES_GRPC_CLIENT_TABLES_CACHE_FILENAME
This commit is contained in:
parent
a7e17d06bb
commit
5c7d4172d2
@ -222,3 +222,9 @@ NEED_CREATE_CACHE_FILES=true
|
||||
|
||||
#NEED_CREATE_CACHE_TEST_FILES - need create "*_cache_test.go" files
|
||||
NEED_CREATE_CACHE_TEST_FILES=true
|
||||
|
||||
#TEMPLATES_GRPC_CLIENT_TABLES_CACHE_FILENAME - short filename of "grpc_client_table_cache.go_" file
|
||||
TEMPLATES_GRPC_CLIENT_TABLES_CACHE_FILENAME="grpc_client_table_cache.go_"
|
||||
|
||||
#TEMPLATES_GRPC_CLIENT_TABLES_CACHE_TEST_FILENAME - short filename of "grpc_client_table_cache.go_" file
|
||||
TEMPLATES_GRPC_CLIENT_TABLES_CACHE_TEST_FILENAME="grpc_client_table_cache.go_"
|
@ -45,7 +45,7 @@ func (crud Crud_DB) Read_ctx(ctx context.Context, m *lawsuit_status_types.Lawsui
|
||||
}
|
||||
|
||||
//удалим из кэша
|
||||
//cache.Remove(m.ID)
|
||||
//cache.Remove(int64(m.ID))
|
||||
|
||||
return err
|
||||
}
|
||||
|
@ -1,6 +1,3 @@
|
||||
//Файл создан автоматически кодогенератором crud_generator
|
||||
//Не изменяйте ничего здесь.
|
||||
|
||||
package grpc_lawsuit_status_types
|
||||
|
||||
import (
|
||||
|
@ -0,0 +1,56 @@
|
||||
package grpc_lawsuit_status_types
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/ManyakRus/starter/log"
|
||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/api/grpc_proto"
|
||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_client"
|
||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_constants"
|
||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc_nrpc"
|
||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/nrpc/nrpc_client"
|
||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ReadFromCache - возвращает модель из БД
|
||||
func (crud Crud_GRPC) ReadFromCache(m *lawsuit_status_types.LawsuitStatusType) error {
|
||||
var err error
|
||||
|
||||
// подключение
|
||||
grpc_client.Connect_GRPC_NRPC()
|
||||
|
||||
// подготовка запроса
|
||||
var versionModel = crud.GetVersionModel()
|
||||
|
||||
Request := &grpc_proto.RequestId{}
|
||||
Request.ID = int64(m.ID)
|
||||
Request.VersionModel = versionModel
|
||||
|
||||
ctxMain := context.Background()
|
||||
ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(grpc_constants.GetTimeoutSeconds()))
|
||||
defer ctxCancelFunc()
|
||||
|
||||
// запрос
|
||||
var Response *grpc_proto.Response
|
||||
if grpc_nrpc.NeedNRPC == true {
|
||||
Response, err = nrpc_client.Client.LawsuitStatusType_ReadFromCache(Request)
|
||||
} else {
|
||||
Response, err = grpc_client.Client.LawsuitStatusType_ReadFromCache(ctx, Request)
|
||||
}
|
||||
if err != nil {
|
||||
if grpc_client.IsErrorModelVersion(err) == true {
|
||||
log.Panic(err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// ответ
|
||||
sModel := Response.ModelString
|
||||
err = json.Unmarshal([]byte(sModel), m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package grpc_lawsuit_status_types
|
||||
|
||||
import (
|
||||
"github.com/ManyakRus/starter/config_main"
|
||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_client"
|
||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestReadFromCache(t *testing.T) {
|
||||
config_main.LoadEnv()
|
||||
grpc_client.Connect()
|
||||
defer grpc_client.CloseConnection()
|
||||
|
||||
crud := Crud_GRPC{}
|
||||
Otvet := lawsuit_status_types.LawsuitStatusType{}
|
||||
Otvet.ID = Postgres_ID_Test
|
||||
err := crud.ReadFromCache(&Otvet)
|
||||
|
||||
if err != nil {
|
||||
t.Error("ReadFromCache() error: ", err)
|
||||
}
|
||||
|
||||
if Otvet.ID == 0 {
|
||||
t.Error("ReadFromCache() error: ID =0")
|
||||
}
|
||||
}
|
@ -52,6 +52,8 @@ type SettingsINI struct {
|
||||
TEMPLATES_GRPC_CLIENT_TABLE_UPDATE_TEST_FILENAME string
|
||||
TEMPLATES_GRPC_SERVER_TABLE_UPDATE_FILENAME string
|
||||
TEMPLATES_GRPC_SERVER_TABLE_UPDATE_TEST_FILENAME string
|
||||
TEMPLATES_GRPC_CLIENT_TABLES_CACHE_FILENAME string
|
||||
TEMPLATES_GRPC_CLIENT_TABLES_CACHE_TEST_FILENAME string
|
||||
NEED_CREATE_MODEL_STRUCT bool
|
||||
NEED_CREATE_MODEL_CRUD bool
|
||||
NEED_CREATE_DB bool
|
||||
@ -468,6 +470,16 @@ func FillSettings() {
|
||||
s = Getenv(Name, true)
|
||||
Settings.NEED_CREATE_CACHE_TEST_FILES = BoolFromString(s)
|
||||
|
||||
//
|
||||
Name = "TEMPLATES_GRPC_CLIENT_TABLES_CACHE_FILENAME"
|
||||
s = Getenv(Name, true)
|
||||
Settings.TEMPLATES_GRPC_CLIENT_TABLES_CACHE_FILENAME = s
|
||||
|
||||
//
|
||||
Name = "TEMPLATES_GRPC_CLIENT_TABLES_CACHE_TEST_FILENAME"
|
||||
s = Getenv(Name, true)
|
||||
Settings.TEMPLATES_GRPC_CLIENT_TABLES_CACHE_TEST_FILENAME = s
|
||||
|
||||
}
|
||||
|
||||
// CurrentDirectory - возвращает текущую директорию ОС
|
||||
|
@ -539,7 +539,7 @@ func CreateFilesUpdateEveryColumn(Table1 *types.Table) error {
|
||||
ModelTableURL := create_files.FindModelTableURL(TableName)
|
||||
TextCrud = create_files.AddImport(TextCrud, ModelTableURL)
|
||||
|
||||
//TextCrud = create_files.ConvertIdToAlias(TextCrud, Table1)
|
||||
TextCrud = create_files.ConvertIdToAlias(TextCrud, Table1)
|
||||
}
|
||||
|
||||
//создание текста
|
||||
@ -692,7 +692,7 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error {
|
||||
ModelTableURL := create_files.FindModelTableURL(TableName)
|
||||
TextCrud = create_files.AddImport(TextCrud, ModelTableURL)
|
||||
|
||||
//TextCrud = create_files.ConvertIdToAlias(TextCrud, Table1)
|
||||
TextCrud = create_files.ConvertIdToAlias(TextCrud, Table1)
|
||||
}
|
||||
|
||||
//создание текста
|
||||
|
@ -58,6 +58,27 @@ func CreateAllFiles(MapAll map[string]*types.Table) error {
|
||||
}
|
||||
|
||||
}
|
||||
//NEED_CREATE_CACHE_API
|
||||
if config.Settings.NEED_CREATE_CACHE_API == true {
|
||||
//файлы grpc_server cache
|
||||
if config.Settings.NEED_CREATE_CACHE_FILES == true {
|
||||
err = CreateFiles_GRPC_Client_Cache(Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateFiles() table: ", Table1.Name, " error: ", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
//тестовые файлы grpc_server cache
|
||||
if config.Settings.NEED_CREATE_CACHE_TEST_FILES == true {
|
||||
err = CreateFiles_GRPC_Client_Cache_Test(Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateTestFiles() table: ", Table1.Name, " error: ", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
@ -91,31 +112,13 @@ func CreateFiles(Table1 *types.Table) error {
|
||||
//заменим имя пакета на новое
|
||||
TextGRPCClient = create_files.ReplacePackageName(TextGRPCClient, DirReadyTable)
|
||||
|
||||
////заменим импорты
|
||||
//if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
// TextGRPCClient = create_files.DeleteTemplateRepositoryImports(TextGRPCClient)
|
||||
//
|
||||
// ConstantsURL := create_files.FindGRPCConstantsURL()
|
||||
// TextGRPCClient = create_files.AddImport(TextGRPCClient, ConstantsURL)
|
||||
//
|
||||
// GRPC_NRPC_URL := create_files.Find_GRPC_NRPC_URL()
|
||||
// TextGRPCClient = create_files.AddImport(TextGRPCClient, GRPC_NRPC_URL)
|
||||
//
|
||||
// DBConstantsURL := create_files.FindDBConstantsURL()
|
||||
// TextGRPCClient = create_files.AddImport(TextGRPCClient, DBConstantsURL)
|
||||
//
|
||||
// //удалим лишние функции
|
||||
// TextGRPCClient = create_files.DeleteFuncDelete(TextGRPCClient, Table1)
|
||||
// TextGRPCClient = create_files.DeleteFuncRestore(TextGRPCClient, Table1)
|
||||
// TextGRPCClient = create_files.DeleteFuncFind_byExtID(TextGRPCClient, Table1)
|
||||
//}
|
||||
|
||||
//создание текста
|
||||
ModelName := Table1.NameGo
|
||||
TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
|
||||
TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
|
||||
TextGRPCClient = config.Settings.TEXT_MODULE_GENERATED + TextGRPCClient
|
||||
|
||||
//заменим импорты
|
||||
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
//TextGRPCClient = create_files.ReplaceServiceURLImports(TextGRPCClient)
|
||||
TextGRPCClient = create_files.DeleteTemplateRepositoryImports(TextGRPCClient)
|
||||
@ -658,3 +661,145 @@ func FindTextUpdateEveryColumnTest1(TextGRPC_ClientUpdateFunc string, Table1 *ty
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// CreateFiles_GRPC_Client_Cache - создаёт 1 файл в папке grpc_client
|
||||
func CreateFiles_GRPC_Client_Cache(Table1 *types.Table) error {
|
||||
var err error
|
||||
|
||||
//чтение файлов
|
||||
DirBin := micro.ProgramDir_bin()
|
||||
DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile()
|
||||
DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile()
|
||||
DirTemplatesCache := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile()
|
||||
DirReadyCache := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile()
|
||||
|
||||
FilenameTemplateGRPCClient := DirTemplatesCache + config.Settings.TEMPLATES_GRPC_CLIENT_TABLES_CACHE_FILENAME
|
||||
TableName := strings.ToLower(Table1.Name)
|
||||
DirReadyTable := DirReadyCache + "grpc_" + TableName + micro.SeparatorFile()
|
||||
FilenameReadyGRPCClient := DirReadyTable + "grpc_" + TableName + "_cache.go"
|
||||
|
||||
//создадим папку готовых файлов
|
||||
folders.CreateFolder(DirReadyTable)
|
||||
|
||||
bytes, err := os.ReadFile(FilenameTemplateGRPCClient)
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateGRPCClient, " error: ", err)
|
||||
}
|
||||
TextGRPCClient := string(bytes)
|
||||
|
||||
//заменим имя пакета на новое
|
||||
TextGRPCClient = create_files.ReplacePackageName(TextGRPCClient, DirReadyTable)
|
||||
|
||||
//создание текста
|
||||
ModelName := Table1.NameGo
|
||||
TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
|
||||
TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
|
||||
TextGRPCClient = config.Settings.TEXT_MODULE_GENERATED + TextGRPCClient
|
||||
|
||||
//заменим импорты
|
||||
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
//TextGRPCClient = create_files.ReplaceServiceURLImports(TextGRPCClient)
|
||||
TextGRPCClient = create_files.DeleteTemplateRepositoryImports(TextGRPCClient)
|
||||
|
||||
//proto
|
||||
RepositoryGRPCProtoURL := create_files.FindProtoURL()
|
||||
TextGRPCClient = create_files.AddImport(TextGRPCClient, RepositoryGRPCProtoURL)
|
||||
|
||||
//model
|
||||
RepositoryModelURL := create_files.FindModelTableURL(TableName)
|
||||
TextGRPCClient = create_files.AddImport(TextGRPCClient, RepositoryModelURL)
|
||||
|
||||
//grpc client
|
||||
RepositoryGRPCClientlURL := create_files.FindGRPClientURL()
|
||||
TextGRPCClient = create_files.AddImport(TextGRPCClient, RepositoryGRPCClientlURL)
|
||||
|
||||
//nrpc client
|
||||
RepositoryNRPCClientlURL := create_files.FindNRPClientURL()
|
||||
TextGRPCClient = create_files.AddImport(TextGRPCClient, RepositoryNRPCClientlURL)
|
||||
|
||||
//constants GRPC
|
||||
RepositoryGRPCConstantsURL := create_files.FindGRPCConstantsURL()
|
||||
TextGRPCClient = create_files.AddImport(TextGRPCClient, RepositoryGRPCConstantsURL)
|
||||
|
||||
//DBConstantsURL := create_files.FindDBConstantsURL()
|
||||
//TextGRPCClient = create_files.AddImport(TextGRPCClient, DBConstantsURL)
|
||||
|
||||
//grpc_nrpc
|
||||
GRPC_NRPC_URL := create_files.Find_GRPC_NRPC_URL()
|
||||
TextGRPCClient = create_files.AddImport(TextGRPCClient, GRPC_NRPC_URL)
|
||||
}
|
||||
|
||||
//удаление пустого импорта
|
||||
TextGRPCClient = create_files.DeleteEmptyImport(TextGRPCClient)
|
||||
|
||||
//удаление пустых строк
|
||||
TextGRPCClient = create_files.DeleteEmptyLines(TextGRPCClient)
|
||||
|
||||
//запись файла
|
||||
err = os.WriteFile(FilenameReadyGRPCClient, []byte(TextGRPCClient), constants.FILE_PERMISSIONS)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// CreateFiles_GRPC_Client_Cache_Test - создаёт 1 файл в папке grpc_client
|
||||
func CreateFiles_GRPC_Client_Cache_Test(Table1 *types.Table) error {
|
||||
var err error
|
||||
|
||||
//чтение файлов
|
||||
DirBin := micro.ProgramDir_bin()
|
||||
DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile()
|
||||
DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile()
|
||||
DirTemplatesCache := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile()
|
||||
DirReadyCache := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile()
|
||||
|
||||
FilenameTemplateCache := DirTemplatesCache + config.Settings.TEMPLATES_GRPC_CLIENT_TABLES_CACHE_TEST_FILENAME
|
||||
TableName := strings.ToLower(Table1.Name)
|
||||
DirReadyTable := DirReadyCache + "grpc_" + TableName + micro.SeparatorFile()
|
||||
FilenameReadyCache := DirReadyTable + "grpc_" + TableName + "_cache_test.go"
|
||||
|
||||
//создадим папку готовых файлов
|
||||
folders.CreateFolder(DirReadyTable)
|
||||
|
||||
bytes, err := os.ReadFile(FilenameTemplateCache)
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateCache, " error: ", err)
|
||||
}
|
||||
TextGRPCClient := string(bytes)
|
||||
|
||||
//заменим имя пакета на новое
|
||||
TextGRPCClient = create_files.ReplacePackageName(TextGRPCClient, DirReadyTable)
|
||||
|
||||
//заменим импорты
|
||||
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
TextGRPCClient = create_files.DeleteTemplateRepositoryImports(TextGRPCClient)
|
||||
|
||||
GRPClientURL := create_files.FindGRPClientURL()
|
||||
TextGRPCClient = create_files.AddImport(TextGRPCClient, GRPClientURL)
|
||||
|
||||
ModelTableName := create_files.FindModelTableURL(TableName)
|
||||
TextGRPCClient = create_files.AddImport(TextGRPCClient, ModelTableName)
|
||||
}
|
||||
|
||||
// замена ID на PrimaryKey
|
||||
TextGRPCClient = create_files.ReplacePrimaryKeyID(TextGRPCClient, Table1)
|
||||
|
||||
//SkipNow()
|
||||
TextGRPCClient = create_files.AddSkipNow(TextGRPCClient, Table1)
|
||||
|
||||
//замена импортов на новые URL
|
||||
TextGRPCClient = create_files.ReplaceServiceURLImports(TextGRPCClient)
|
||||
|
||||
//удаление пустого импорта
|
||||
TextGRPCClient = create_files.DeleteEmptyImport(TextGRPCClient)
|
||||
|
||||
//удаление пустых строк
|
||||
TextGRPCClient = create_files.DeleteEmptyLines(TextGRPCClient)
|
||||
|
||||
//добавим комментарий в начало файла
|
||||
TextGRPCClient = config.Settings.TEXT_MODULE_GENERATED + TextGRPCClient
|
||||
|
||||
//запись файла
|
||||
err = os.WriteFile(FilenameReadyCache, []byte(TextGRPCClient), constants.FILE_PERMISSIONS)
|
||||
|
||||
return err
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ func CreateAllFiles(MapAll map[string]*types.Table) error {
|
||||
|
||||
}
|
||||
|
||||
//UPDATE_EVERY_COLUMN
|
||||
//NEED_CREATE_CACHE_API
|
||||
if config.Settings.NEED_CREATE_CACHE_API == true {
|
||||
//файлы grpc_server cache
|
||||
if config.Settings.NEED_CREATE_CACHE_FILES == true {
|
||||
|
Loading…
Reference in New Issue
Block a user