mirror of
https://github.com/ManyakRus/crud_generator.git
synced 2024-11-30 08:47:02 +02:00
сделал settings.txt
This commit is contained in:
parent
4cc1fe81d4
commit
7049b225e3
151
bin/copy/rapira/templates/configs_/settings.txt
Normal file
151
bin/copy/rapira/templates/configs_/settings.txt
Normal file
@ -0,0 +1,151 @@
|
||||
#---------------------Database settings---------------------
|
||||
#DB_HOST - Database server name or ip-address. Only Postgres SQL
|
||||
DB_HOST=""
|
||||
|
||||
#DB_NAME - Database table name
|
||||
DB_NAME=""
|
||||
|
||||
#DB_SCHEME - Database schema name
|
||||
DB_SCHEME="public"
|
||||
|
||||
#DB_PORT - Database port number
|
||||
DB_PORT="5432"
|
||||
|
||||
#DB_USER - Database login (user)
|
||||
DB_USER=""
|
||||
|
||||
#DB_PASSWORD - Database login password
|
||||
DB_PASSWORD=""
|
||||
|
||||
#INCLUDE_TABLES - table name filter. Regular expression
|
||||
INCLUDE_TABLES=""
|
||||
|
||||
#INCLUDE_TABLES - table name ignore filter. Regular expression
|
||||
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_NAME - service name for your new service
|
||||
SERVICE_NAME=sync_service
|
||||
|
||||
#TEMPLATE_SERVICE_NAME - service name in your template files
|
||||
TEMPLATE_SERVICE_NAME=sync_service
|
||||
|
||||
#TEMPLATE_REPOSITORY_URL - repository URL in template files
|
||||
TEMPLATE_REPOSITORY_URL="gitlab.aescorp.ru/dsp_dev/claim/sync_service"
|
||||
|
||||
#same folder names uses for read template files and create new files
|
||||
#TEMPLATE_FOLDERNAME - filder name in your computer with templates
|
||||
TEMPLATE_FOLDERNAME="templates"
|
||||
|
||||
#TEMPLATE_FOLDERNAME_MAIN - folder name for create models (golang struct with all table fields)
|
||||
TEMPLATE_FOLDERNAME_MAIN="cmd"
|
||||
|
||||
#TEMPLATE_FOLDERNAME_MODEL - folder name for create models (golang struct with all table fields)
|
||||
TEMPLATE_FOLDERNAME_MODEL="pkg/object_model/entities"
|
||||
|
||||
#TEMPLATE_FOLDERNAME_DB - folder name for create database crud operations
|
||||
TEMPLATE_FOLDERNAME_CRUD="pkg/db/crud"
|
||||
|
||||
#TEMPLATE_FOLDERNAME_TABLES - folder name for create database tables models
|
||||
TEMPLATE_FOLDERNAME_TABLES="pkg/db/tables"
|
||||
|
||||
#TEMPLATE_FOLDERNAME_DB - folder name for create db constants
|
||||
TEMPLATE_FOLDERNAME_DB="pkg/db"
|
||||
|
||||
|
||||
#TEMPLATE_FOLDERNAME_GRPC - folder name for create .proto file
|
||||
TEMPLATE_FOLDERNAME_GRPC_PROTO="pkg/network/grpc"
|
||||
|
||||
#TEMPLATE_FOLDERNAME_GRPC - folder name for grpc
|
||||
TEMPLATE_FOLDERNAME_GRPC="pkg/network/grpc"
|
||||
|
||||
#TEMPLATE_FOLDERNAME_GRPC_SERVER - filder name for create grpc server files
|
||||
TEMPLATE_FOLDERNAME_GRPC_SERVER="internal/server_grpc"
|
||||
|
||||
#TEMPLATE_FOLDERNAME_GRPC_CLIENT - folder name for create grpc client files
|
||||
TEMPLATE_FOLDERNAME_GRPC_CLIENT="pkg/network/grpc/grpc_client"
|
||||
|
||||
#TEMPLATE_FOLDERNAME_NRPC_SERVER - folder name for create nrpc server files
|
||||
TEMPLATE_FOLDERNAME_NRPC_SERVER="internal/server_nrpc"
|
||||
|
||||
#TEMPLATE_FOLDERNAME_NRPC - folder name for create common nrpc files
|
||||
TEMPLATE_FOLDERNAME_NRPC="pkg/network/nrpc"
|
||||
|
||||
#TEMPLATE_FOLDERNAME_NRPC_CLIENT - foldr name for create nrpc client files
|
||||
TEMPLATE_FOLDERNAME_NRPC_CLIENT="pkg/network/nrpc/nrpc_client"
|
||||
|
||||
#TEMPLATE_FOLDERNAME_CRUD_STARTER - folder name for create crud_starter.go file
|
||||
TEMPLATE_FOLDERNAME_CRUD_STARTER="pkg/crud_starter"
|
||||
|
||||
#TEMPLATE_FOLDERNAME_ALIAS - folder name for create alias.go file, with go types with aliases
|
||||
TEMPLATE_FOLDERNAME_ALIAS="pkg/object_model/types/alias"
|
||||
|
||||
#TEXT_TEMPLATE_MODEL - model name text in templates, for replace to new model names
|
||||
TEXT_TEMPLATE_MODEL="LawsuitStatusType"
|
||||
|
||||
#TEXT_TEMPLATE_TABLENAME - table name text in tamplates, for replace to new table names
|
||||
TEXT_TEMPLATE_TABLENAME="lawsuit_status_types"
|
||||
|
||||
#USE_DEFAULT_TEMPLATE - "true" will do default text replaces. "false" - for use own templates
|
||||
USE_DEFAULT_TEMPLATE=true
|
||||
|
||||
#HAS_IS_DELETED - fill "true" if you have "is_deleted" column, and want Delete() Restore() functions.
|
||||
HAS_IS_DELETED=true
|
||||
|
||||
#---------------------Create files settings---------------------
|
||||
|
||||
#NEED_CREATE_CRUD - fill "true" if you want create crud operations files
|
||||
NEED_CREATE_CRUD=true
|
||||
|
||||
#NEED_CREATE_GRPC - fill "true" if you want create grpc operations files
|
||||
NEED_CREATE_GRPC=true
|
||||
|
||||
#NEED_CREATE_NRPC - fill "true" if you want create nrpc operations files (need NATS message query server)
|
||||
NEED_CREATE_NRPC=true
|
||||
|
||||
#NEED_CREATE_MODEL_STRUCT - fill "true" if you want create model files with golang struct with all database fields
|
||||
NEED_CREATE_MODEL_STRUCT=true
|
||||
|
||||
#NEED_CREATE_MODEL_CRUD - fill "true" if you want create crud operations in model files
|
||||
NEED_CREATE_MODEL_CRUD=true
|
||||
|
||||
#NEED_CREATE_DB_TEST - fill "true" if you want create DB _test.go files
|
||||
NEED_CREATE_DB_TEST=true
|
||||
|
||||
#NEED_CREATE_DB - fill "true" if you want create DB .go files
|
||||
NEED_CREATE_DB=true
|
||||
|
||||
#NEED_CREATE_GRPC_SERVER_TEST - fill "true" if you want create GRPC server _test.go files
|
||||
NEED_CREATE_GRPC_SERVER_TEST=true
|
||||
|
||||
#NEED_CREATE_GRPC_CLIENT_TEST - fill "true" if you want create GRPC client _test.go files
|
||||
NEED_CREATE_GRPC_CLIENT_TEST=true
|
||||
|
||||
#NEED_CREATE_NRPC_SERVER_TEST - fill "true" if you want create NRPC server _test.go files
|
||||
NEED_CREATE_NRPC_SERVER_TEST=true
|
||||
|
||||
#NEED_CREATE_NRPC_CLIENT_TEST - fill "true" if you want create NRPC client _test.go files
|
||||
NEED_CREATE_NRPC_CLIENT_TEST=true
|
||||
|
||||
#PREFIX_SERVER_GRPC - filename prefix for grpc server files
|
||||
PREFIX_SERVER_GRPC="server_grpc_"
|
||||
|
||||
#PREFIC_CRUD - filename prefix for crud database files
|
||||
PREFIX_CRUD="crud_"
|
||||
|
||||
#PREFIX_TABLE - filename prefix for database table model files
|
||||
PREFIX_TABLE="table_"
|
||||
|
||||
#PREFIX_MODEL - filename prefix for view model files
|
||||
PREFIX_MODEL=""
|
||||
|
||||
#COMMENT_MODEL_STRUCT - fill comments to every model structure
|
||||
COMMENT_MODEL_STRUCT="модель для таблицы "
|
||||
|
||||
#TEXT_MODULE_GENERATED - comment text for every module file
|
||||
TEXT_MODULE_GENERATED="//Файл создан автоматически кодогенератором crud_generator\n//Не изменяйте ничего здесь.\n\n"
|
||||
|
@ -5,6 +5,8 @@ FILEMAIN=./cmd/$(SERVICENAME)/main.go
|
||||
FILEAPP=./bin/$(SERVICENAME)
|
||||
|
||||
NEW_REPO=$(SERVICENAME)
|
||||
CD_GENERATION_PROTO=cd ./pkg/network/grpc
|
||||
GENERATION_PROTO=generation_code.sh
|
||||
|
||||
|
||||
run:
|
||||
@ -52,4 +54,6 @@ conn:
|
||||
init:
|
||||
clear
|
||||
go mod init gitlab.aescorp.ru/dsp_dev/claim/sync_service
|
||||
$(CD_GENERATION_PROTO)
|
||||
$(GENERATION_PROTO)
|
||||
go mod tidy
|
@ -2,6 +2,7 @@ package server_grpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/ManyakRus/starter/micro"
|
||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_proto"
|
||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
|
||||
)
|
||||
|
114
bin/templates/pkg/network/nrpc/nrpc_client.go_
Normal file
114
bin/templates/pkg/network/nrpc/nrpc_client.go_
Normal file
@ -0,0 +1,114 @@
|
||||
package nrpc_client
|
||||
|
||||
import (
|
||||
"github.com/ManyakRus/starter/contextmain"
|
||||
"github.com/ManyakRus/starter/log"
|
||||
"github.com/ManyakRus/starter/stopapp"
|
||||
"github.com/nats-io/nats.go"
|
||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/constants"
|
||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_proto"
|
||||
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type SettingsINI struct {
|
||||
NATS_HOST string
|
||||
NATS_PORT string
|
||||
}
|
||||
|
||||
var Settings SettingsINI
|
||||
|
||||
// Conn - подключение к NATS
|
||||
var Conn *nats.Conn
|
||||
|
||||
// Client - подключение к клиенту NRPC
|
||||
var Client *grpc_proto.Sync_serviceClient
|
||||
|
||||
// Connect - подключается к NATS
|
||||
func Connect() {
|
||||
var err error
|
||||
|
||||
if Settings.NATS_HOST == "" {
|
||||
FillSettings()
|
||||
}
|
||||
|
||||
NatsURL := "nats://" + Settings.NATS_HOST + ":" + Settings.NATS_PORT
|
||||
// Connect to the NATS server.
|
||||
Conn, err = nats.Connect(NatsURL, nats.Timeout(5*time.Second))
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
// defer Conn.Close()
|
||||
|
||||
// This is our generated client.
|
||||
Client = grpc_proto.NewSync_serviceClient(Conn)
|
||||
|
||||
log.Info("Client NRPC connected: ", NatsURL)
|
||||
}
|
||||
|
||||
// FillSettings - заполняет настройки из переменных окружения
|
||||
func FillSettings() {
|
||||
Settings = SettingsINI{}
|
||||
Settings.NATS_HOST = os.Getenv("BUS_LOCAL_HOST")
|
||||
Settings.NATS_PORT = os.Getenv("BUS_LOCAL_PORT")
|
||||
|
||||
if Settings.NATS_HOST == "" {
|
||||
log.Panic("Need fill BUS_LOCAL_HOST ! in OS Environment ")
|
||||
}
|
||||
|
||||
if Settings.NATS_PORT == "" {
|
||||
log.Panic("Need fill BUS_LOCAL_PORT ! in OS Environment ")
|
||||
}
|
||||
}
|
||||
|
||||
// WaitStop - ожидает отмену глобального контекста
|
||||
func WaitStop() {
|
||||
|
||||
select {
|
||||
case <-contextmain.GetContext().Done():
|
||||
log.Warn("Context app is canceled. nrpc client connect")
|
||||
}
|
||||
|
||||
// ждём пока отправляемых сейчас сообщений будет =0
|
||||
stopapp.WaitTotalMessagesSendingNow("sync_service_client")
|
||||
|
||||
// закрываем соединение
|
||||
CloseConnection()
|
||||
stopapp.GetWaitGroup_Main().Done()
|
||||
}
|
||||
|
||||
// Start - необходимые процедуры для запуска сервера NRPC
|
||||
func Start() {
|
||||
Connect()
|
||||
|
||||
stopapp.GetWaitGroup_Main().Add(1)
|
||||
go WaitStop()
|
||||
|
||||
}
|
||||
|
||||
// CloseConnection - закрывает подключение к NATS
|
||||
func CloseConnection() {
|
||||
Conn.Close()
|
||||
log.Info("NRPC client connection closed")
|
||||
}
|
||||
|
||||
// IsRecordNotFound - возвращает true если ошибка = "record not found"
|
||||
func IsRecordNotFound(err error) bool {
|
||||
Otvet := false
|
||||
|
||||
if err == nil {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// len1 := len(constants.TEXT_RECORD_NOT_FOUND)
|
||||
TextErr := err.Error()
|
||||
pos1 := strings.Index(TextErr, constants.TEXT_RECORD_NOT_FOUND)
|
||||
// if TextErr[0:len1] == constants.TEXT_RECORD_NOT_FOUND {
|
||||
if pos1 >= 0 {
|
||||
Otvet = true
|
||||
}
|
||||
|
||||
return Otvet
|
||||
}
|
13
bin/templates/pkg/network/nrpc/nrpc_client_test.go_
Normal file
13
bin/templates/pkg/network/nrpc/nrpc_client_test.go_
Normal file
@ -0,0 +1,13 @@
|
||||
package nrpc_client
|
||||
|
||||
import (
|
||||
"github.com/ManyakRus/starter/config"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestConnect(t *testing.T) {
|
||||
config.LoadEnv()
|
||||
FillSettings()
|
||||
Connect()
|
||||
CloseConnection()
|
||||
}
|
@ -16,3 +16,5 @@ const TemplateFilenameCrudGo = "crud.go_"
|
||||
const TemplateFilenameCrudGoTest = "crud_test.go_"
|
||||
|
||||
const SETTINGS_FOLDER_NAME = "templates/configs_"
|
||||
|
||||
const GENERATION_PROTO_FILENAME = "generation_code.sh"
|
||||
|
@ -297,8 +297,8 @@ func FindNRPCServerlURL() string {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// FindProtoURL - возвращает URL репозитория с файлом .proto
|
||||
func FindProtoURL() string {
|
||||
// FindProtobufURL - возвращает URL репозитория с файлом .proto
|
||||
func FindProtobufURL() string {
|
||||
Otvet := ""
|
||||
|
||||
Otvet = config.Settings.SERVICE_REPOSITORY_URL + "/" + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO
|
||||
@ -324,8 +324,8 @@ func FindTableNameURL(TableName string) string {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// FindGRPCProtoURL - возвращает URL репозитория с пакетом "grpc_proto"
|
||||
func FindGRPCProtoURL() string {
|
||||
// FindProtoURL - возвращает URL репозитория с пакетом "grpc_proto"
|
||||
func FindProtoURL() string {
|
||||
Otvet := ""
|
||||
|
||||
Otvet = config.Settings.SERVICE_REPOSITORY_URL + "/" + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + "/" + "grpc_proto"
|
||||
|
@ -83,7 +83,8 @@ func CreateFiles(Table1 *types.Table) error {
|
||||
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
TextDB = create_files.DeleteTemplateRepositoryImports(TextDB)
|
||||
|
||||
TextDB = create_files.AddImport(TextDB, DirReadyTable)
|
||||
ModelTableURL := create_files.FindModelTableURL(TableName)
|
||||
TextDB = create_files.AddImport(TextDB, ModelTableURL)
|
||||
|
||||
ConstantsURL := create_files.FindGRPCConstantsURL()
|
||||
TextDB = create_files.AddImport(TextDB, ConstantsURL)
|
||||
@ -156,10 +157,11 @@ func CreateTestFiles(Table1 *types.Table) error {
|
||||
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
TextDB = create_files.DeleteTemplateRepositoryImports(TextDB)
|
||||
|
||||
TextDB = create_files.AddImport(TextDB, DirReadyTable)
|
||||
ModelTableURL := create_files.FindModelTableURL(TableName)
|
||||
TextDB = create_files.AddImport(TextDB, ModelTableURL)
|
||||
|
||||
ConstantsURL := create_files.FindGRPCConstantsURL()
|
||||
TextDB = create_files.AddImport(TextDB, ConstantsURL)
|
||||
//ConstantsURL := create_files.FindGRPCConstantsURL()
|
||||
//TextDB = create_files.AddImport(TextDB, ConstantsURL)
|
||||
}
|
||||
|
||||
//создание текста
|
||||
|
@ -60,7 +60,7 @@ func CreateGRPCClient() error {
|
||||
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
TextGRPCClient = create_files.DeleteTemplateRepositoryImports(TextGRPCClient)
|
||||
|
||||
ProtoURL := create_files.FindGRPCProtoURL()
|
||||
ProtoURL := create_files.FindProtoURL()
|
||||
TextGRPCClient = create_files.AddImport(TextGRPCClient, ProtoURL)
|
||||
|
||||
DBConstantsURL := create_files.FindDBConstantsURL()
|
||||
|
@ -84,8 +84,8 @@ func CreateFiles(Table1 *types.Table) error {
|
||||
ConstantsURL := create_files.FindGRPCConstantsURL()
|
||||
TextGRPCClient = create_files.AddImport(TextGRPCClient, ConstantsURL)
|
||||
|
||||
ProtoURL := create_files.FindProtoURL()
|
||||
TextGRPCClient = create_files.AddImport(TextGRPCClient, ProtoURL)
|
||||
//ProtoURL := create_files.FindProtobufURL()
|
||||
//TextGRPCClient = create_files.AddImport(TextGRPCClient, ProtoURL)
|
||||
}
|
||||
|
||||
//создание текста
|
||||
@ -110,7 +110,7 @@ func CreateFiles(Table1 *types.Table) error {
|
||||
TextGRPCClient = create_files.DeleteTemplateRepositoryImports(TextGRPCClient)
|
||||
|
||||
//proto
|
||||
RepositoryGRPCProtoURL := create_files.FindGRPCProtoURL()
|
||||
RepositoryGRPCProtoURL := create_files.FindProtoURL()
|
||||
TextGRPCClient = create_files.AddImport(TextGRPCClient, RepositoryGRPCProtoURL)
|
||||
|
||||
//model
|
||||
|
@ -96,15 +96,15 @@ func CreateFiles(Table1 *types.Table) error {
|
||||
|
||||
//замена импортов на новые URL
|
||||
//TextGRPCServer = create_files.ReplaceServiceURLImports(TextGRPCServer)
|
||||
TextGRPCServer = create_files.DeleteTemplateRepositoryImports(TextGRPCServer)
|
||||
//TextGRPCServer = create_files.DeleteTemplateRepositoryImports(TextGRPCServer)
|
||||
|
||||
//proto
|
||||
RepositoryGRPCProtoURL := create_files.FindGRPCProtoURL()
|
||||
TextGRPCServer = create_files.AddImport(TextGRPCServer, RepositoryGRPCProtoURL)
|
||||
|
||||
//model
|
||||
RepositoryModelURL := create_files.FindModelTableURL(TableName)
|
||||
TextGRPCServer = create_files.AddImport(TextGRPCServer, RepositoryModelURL)
|
||||
////proto
|
||||
//RepositoryGRPCProtoURL := create_files.FindProtoURL()
|
||||
//TextGRPCServer = create_files.AddImport(TextGRPCServer, RepositoryGRPCProtoURL)
|
||||
//
|
||||
////model
|
||||
//RepositoryModelURL := create_files.FindModelTableURL(TableName)
|
||||
//TextGRPCServer = create_files.AddImport(TextGRPCServer, RepositoryModelURL)
|
||||
}
|
||||
|
||||
//запись файла
|
||||
@ -145,8 +145,8 @@ func CreateTestFiles(Table1 *types.Table) error {
|
||||
ModelTableURL := create_files.FindModelTableURL(TableName)
|
||||
TextGRPCServer = create_files.AddImport(TextGRPCServer, ModelTableURL)
|
||||
|
||||
ProtoURL := create_files.FindProtoURL()
|
||||
TextGRPCServer = create_files.AddImport(TextGRPCServer, ProtoURL)
|
||||
//ProtoURL := create_files.FindProtobufURL()
|
||||
//TextGRPCServer = create_files.AddImport(TextGRPCServer, ProtoURL)
|
||||
|
||||
CrudStarterURL := create_files.FindCrudStarterURL()
|
||||
TextGRPCServer = create_files.AddImport(TextGRPCServer, CrudStarterURL)
|
||||
@ -177,7 +177,7 @@ func CreateTestFiles(Table1 *types.Table) error {
|
||||
TextGRPCServer = create_files.AddSkipNow(TextGRPCServer, Table1)
|
||||
|
||||
//замена импортов на новые URL
|
||||
TextGRPCServer = create_files.ReplaceServiceURLImports(TextGRPCServer)
|
||||
//TextGRPCServer = create_files.ReplaceServiceURLImports(TextGRPCServer)
|
||||
|
||||
//запись файла
|
||||
err = os.WriteFile(FilenameReadyGRPCServer, []byte(TextGRPCServer), constants.FILE_PERMISSIONS)
|
||||
|
@ -52,8 +52,45 @@ func CreateMakefile() error {
|
||||
//ReplaceAll
|
||||
TextMakefile = strings.ReplaceAll(TextMakefile, config.Settings.TEMPLATE_SERVICE_NAME, strings.ToLower(config.Settings.SERVICE_NAME))
|
||||
|
||||
//заполним SERVICEURL
|
||||
VariableName := "SERVICEURL"
|
||||
Value := config.Settings.SERVICE_REPOSITORY_URL
|
||||
TextMakefile = ReplaceVariable(TextMakefile, VariableName, Value)
|
||||
|
||||
//заполним GENERATION_PROTO
|
||||
VariableName = "CD_GENERATION_PROTO"
|
||||
Value = "cd ./" + config.Settings.TEMPLATE_FOLDERNAME_GRPC + " && \\"
|
||||
TextMakefile = ReplaceVariable(TextMakefile, VariableName, Value)
|
||||
|
||||
//заполним GENERATION_PROTO
|
||||
VariableName = "GENERATION_PROTO"
|
||||
Value = "./" + constants.GENERATION_PROTO_FILENAME
|
||||
TextMakefile = ReplaceVariable(TextMakefile, VariableName, Value)
|
||||
|
||||
//запись файла
|
||||
err = os.WriteFile(FilenameReadyMakefile, []byte(TextMakefile), constants.FILE_PERMISSIONS)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// ReplaceVariable - заменяет переменную в тексте
|
||||
func ReplaceVariable(Text, VariableName, Value string) string {
|
||||
Otvet := Text
|
||||
|
||||
pos1 := strings.Index(Otvet, "\n"+VariableName)
|
||||
if pos1 < 0 {
|
||||
//нет такого
|
||||
Otvet = Otvet + "\n" + VariableName + " = " + Value
|
||||
return Otvet
|
||||
}
|
||||
|
||||
s2 := Text[pos1+1:]
|
||||
posEnd := strings.Index(s2, "\n")
|
||||
if posEnd < 0 {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
Otvet = Otvet[:pos1+1] + VariableName + "=" + Value + Otvet[pos1+1+posEnd:]
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
@ -1,312 +1 @@
|
||||
package nrpc_client
|
||||
|
||||
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/types"
|
||||
"github.com/ManyakRus/starter/log"
|
||||
"github.com/ManyakRus/starter/micro"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// CreateAllFiles - создаёт все файлы в папке nrpc_client
|
||||
func CreateAllFiles(MapAll map[string]*types.Table) error {
|
||||
var err error
|
||||
|
||||
for _, Table1 := range MapAll {
|
||||
//проверка что таблица нормальная
|
||||
err1 := create_files.CheckGoodTable(Table1)
|
||||
if err1 != nil {
|
||||
log.Warn(err1)
|
||||
continue
|
||||
}
|
||||
|
||||
//файлы nrpc_client
|
||||
err = CreateFiles(Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateFiles() table: ", Table1.Name, " error: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
//тестовые файлы nrpc_client
|
||||
if config.Settings.NEED_CREATE_NRPC_CLIENT_TEST == true {
|
||||
err = CreateTestFiles(Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateTestFiles() table: ", Table1.Name, " error: ", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// CreateFiles - создаёт 1 файл в папке nrpc_client
|
||||
func CreateFiles(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()
|
||||
DirTemplatesNRPCClient := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_NRPC_CLIENT + micro.SeparatorFile()
|
||||
DirReadyNRPCClient := DirReady + config.Settings.TEMPLATE_FOLDERNAME_NRPC_CLIENT + micro.SeparatorFile()
|
||||
|
||||
FilenameTemplateNRPCClient := DirTemplatesNRPCClient + "nrpc_client.go_"
|
||||
TableName := strings.ToLower(Table1.Name)
|
||||
DirReadyTable := DirReadyNRPCClient + "nrpc_" + TableName + micro.SeparatorFile()
|
||||
FilenameReadyNRPCClient := DirReadyTable + "nrpc_" + TableName + ".go"
|
||||
|
||||
//создадим каталог
|
||||
ok, err := micro.FileExists(DirReadyTable)
|
||||
if ok == false {
|
||||
err = os.MkdirAll(DirReadyTable, 0777)
|
||||
if err != nil {
|
||||
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
bytes, err := os.ReadFile(FilenameTemplateNRPCClient)
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateNRPCClient, " error: ", err)
|
||||
}
|
||||
TextNRPCClient := string(bytes)
|
||||
|
||||
//заменим имя пакета на новое
|
||||
create_files.ReplacePackageName(TextNRPCClient, DirReadyTable)
|
||||
|
||||
//заменим импорты
|
||||
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
TextNRPCClient = create_files.DeleteTemplateRepositoryImports(TextNRPCClient)
|
||||
|
||||
GRPCProtoURL := create_files.FindGRPCProtoURL()
|
||||
TextNRPCClient = create_files.AddImport(TextNRPCClient, GRPCProtoURL)
|
||||
|
||||
NRPCClientURL := create_files.FindNRPCClientURL()
|
||||
TextNRPCClient = create_files.AddImport(TextNRPCClient, NRPCClientURL)
|
||||
|
||||
GRPCConstantsURL := create_files.FindGRPCConstantsURL()
|
||||
TextNRPCClient = create_files.AddImport(TextNRPCClient, GRPCConstantsURL)
|
||||
|
||||
TableURL := create_files.FindModelTableURL(TableName)
|
||||
TextNRPCClient = create_files.AddImport(TextNRPCClient, TableURL)
|
||||
}
|
||||
|
||||
//создание текста
|
||||
ModelName := Table1.NameGo
|
||||
TextNRPCClient = strings.ReplaceAll(TextNRPCClient, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
|
||||
TextNRPCClient = strings.ReplaceAll(TextNRPCClient, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
|
||||
TextNRPCClient = config.Settings.TEXT_MODULE_GENERATED + TextNRPCClient
|
||||
|
||||
if config.Settings.HAS_IS_DELETED == true {
|
||||
TextNRPCClient = DeleteFuncDelete(TextNRPCClient, ModelName, Table1)
|
||||
//TextNRPCClient = DeleteFuncDeleteCtx(TextNRPCClient, ModelName, Table1)
|
||||
TextNRPCClient = DeleteFuncRestore(TextNRPCClient, ModelName, Table1)
|
||||
//TextNRPCClient = DeleteFuncRestoreCtx(TextNRPCClient, ModelName, Table1)
|
||||
}
|
||||
TextNRPCClient = DeleteFuncFind_byExtID(TextNRPCClient, ModelName, Table1)
|
||||
|
||||
//замена импортов на новые URL
|
||||
TextNRPCClient = create_files.ReplaceServiceURLImports(TextNRPCClient)
|
||||
|
||||
//запись файла
|
||||
err = os.WriteFile(FilenameReadyNRPCClient, []byte(TextNRPCClient), constants.FILE_PERMISSIONS)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// CreateTestFiles - создаёт 1 файл в папке nrpc_client
|
||||
func CreateTestFiles(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()
|
||||
DirTemplatesNRPCClient := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_NRPC_CLIENT + micro.SeparatorFile()
|
||||
DirReadyNRPCClient := DirReady + config.Settings.TEMPLATE_FOLDERNAME_NRPC_CLIENT + micro.SeparatorFile()
|
||||
|
||||
FilenameTemplateNRPCClient := DirTemplatesNRPCClient + "nrpc_client_test.go_"
|
||||
TableName := strings.ToLower(Table1.Name)
|
||||
DirReadyTable := DirReadyNRPCClient + "nrpc_" + TableName + micro.SeparatorFile()
|
||||
FilenameReadyNRPCClient := DirReadyTable + "nrpc_" + TableName + "_test.go"
|
||||
|
||||
//создадим каталог
|
||||
ok, err := micro.FileExists(DirReadyTable)
|
||||
if ok == false {
|
||||
err = os.MkdirAll(DirReadyTable, 0777)
|
||||
if err != nil {
|
||||
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
bytes, err := os.ReadFile(FilenameTemplateNRPCClient)
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateNRPCClient, " error: ", err)
|
||||
}
|
||||
TextNRPCClient := string(bytes)
|
||||
|
||||
//заменим имя пакета на новое
|
||||
create_files.ReplacePackageName(TextNRPCClient, DirReadyTable)
|
||||
|
||||
//заменим импорты
|
||||
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
TextNRPCClient = create_files.DeleteTemplateRepositoryImports(TextNRPCClient)
|
||||
|
||||
NRPCClientURL := create_files.FindNRPCClientURL()
|
||||
TextNRPCClient = create_files.AddImport(TextNRPCClient, NRPCClientURL)
|
||||
|
||||
TableURL := create_files.FindModelTableURL(TableName)
|
||||
TextNRPCClient = create_files.AddImport(TextNRPCClient, TableURL)
|
||||
}
|
||||
|
||||
//создание текста
|
||||
ModelName := Table1.NameGo
|
||||
TextNRPCClient = strings.ReplaceAll(TextNRPCClient, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
|
||||
TextNRPCClient = strings.ReplaceAll(TextNRPCClient, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
|
||||
TextNRPCClient = config.Settings.TEXT_MODULE_GENERATED + TextNRPCClient
|
||||
|
||||
if config.Settings.HAS_IS_DELETED == true {
|
||||
TextNRPCClient = DeleteFuncTestDelete(TextNRPCClient, ModelName, Table1)
|
||||
TextNRPCClient = DeleteFuncTestRestore(TextNRPCClient, ModelName, Table1)
|
||||
}
|
||||
TextNRPCClient = DeleteFuncTestFind_byExtID(TextNRPCClient, ModelName, Table1)
|
||||
|
||||
//Postgres_ID_Test = ID Minimum
|
||||
if Table1.IDMinimum != "" {
|
||||
TextFind := "const Postgres_ID_Test = "
|
||||
TextNRPCClient = strings.ReplaceAll(TextNRPCClient, TextFind+"1", TextFind+Table1.IDMinimum)
|
||||
}
|
||||
|
||||
// замена ID на PrimaryKey
|
||||
TextNRPCClient = create_files.ReplacePrimaryKeyID(TextNRPCClient, Table1)
|
||||
|
||||
//SkipNow()
|
||||
TextNRPCClient = create_files.AddSkipNow(TextNRPCClient, Table1)
|
||||
|
||||
//замена импортов на новые URL
|
||||
TextNRPCClient = create_files.ReplaceServiceURLImports(TextNRPCClient)
|
||||
|
||||
//запись файла
|
||||
err = os.WriteFile(FilenameReadyNRPCClient, []byte(TextNRPCClient), constants.FILE_PERMISSIONS)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// DeleteFuncDelete - удаляет функцию Delete()
|
||||
func DeleteFuncDelete(Text, ModelName string, Table1 *types.Table) string {
|
||||
Otvet := Text
|
||||
|
||||
_, ok := Table1.MapColumns["is_deleted"]
|
||||
if ok == true {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
Otvet = create_files.DeleteFuncFromComment(Text, "\n// Delete ")
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// DeleteFuncRestore - удаляет функцию Restore()
|
||||
func DeleteFuncRestore(Text, ModelName string, Table1 *types.Table) string {
|
||||
Otvet := Text
|
||||
|
||||
_, ok := Table1.MapColumns["is_deleted"]
|
||||
if ok == true {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
Otvet = create_files.DeleteFuncFromComment(Text, "\n// Restore ")
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// DeleteFuncDeleteCtx - удаляет функцию Delete_ctx()
|
||||
func DeleteFuncDeleteCtx(Text, ModelName string, Table1 *types.Table) string {
|
||||
Otvet := Text
|
||||
|
||||
_, ok := Table1.MapColumns["is_deleted"]
|
||||
if ok == true {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
Otvet = create_files.DeleteFuncFromComment(Text, "\n// Delete_ctx ")
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// DeleteFuncRestoreCtx - удаляет функцию Restore_ctx()
|
||||
func DeleteFuncRestoreCtx(Text, ModelName string, Table1 *types.Table) string {
|
||||
Otvet := Text
|
||||
|
||||
_, ok := Table1.MapColumns["is_deleted"]
|
||||
if ok == true {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
Otvet = create_files.DeleteFuncFromComment(Text, "\n// Restore_ctx ")
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// DeleteFuncFind_byExtID - удаляет функцию Find_ByExtID()
|
||||
func DeleteFuncFind_byExtID(Text, ModelName string, Table1 *types.Table) string {
|
||||
Otvet := Text
|
||||
|
||||
//если есть обе колонки - ничего не делаем
|
||||
ok := create_files.Has_Column_ExtID_ConnectionID(Table1)
|
||||
if ok == true {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
//
|
||||
Otvet = create_files.DeleteFuncFromComment(Text, "\n// Find_ByExtID ")
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// DeleteFuncTestDelete - удаляет функцию Delete()
|
||||
func DeleteFuncTestDelete(Text, ModelName string, Table1 *types.Table) string {
|
||||
Otvet := Text
|
||||
|
||||
_, ok := Table1.MapColumns["is_deleted"]
|
||||
if ok == true {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
Otvet = create_files.DeleteFuncFromFuncName(Otvet, "TestDelete")
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// DeleteFuncTestRestore - удаляет функцию Restore()
|
||||
func DeleteFuncTestRestore(Text, ModelName string, Table1 *types.Table) string {
|
||||
Otvet := Text
|
||||
|
||||
_, ok := Table1.MapColumns["is_deleted"]
|
||||
if ok == true {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
Otvet = create_files.DeleteFuncFromFuncName(Otvet, "TestRestore")
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// DeleteFuncFind_byExtID - удаляет функцию Find_ByExtID()
|
||||
func DeleteFuncTestFind_byExtID(Text, ModelName string, Table1 *types.Table) string {
|
||||
Otvet := Text
|
||||
|
||||
//если есть обе колонки - ничего не делаем
|
||||
ok := create_files.Has_Column_ExtID_ConnectionID(Table1)
|
||||
if ok == true {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
Otvet = create_files.DeleteFuncFromFuncName(Otvet, "TestFindByExtID")
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
312
internal/create_files/nrpc_client_tables/nrpc_client_tables.go
Normal file
312
internal/create_files/nrpc_client_tables/nrpc_client_tables.go
Normal file
@ -0,0 +1,312 @@
|
||||
package nrpc_client_tables
|
||||
|
||||
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/types"
|
||||
"github.com/ManyakRus/starter/log"
|
||||
"github.com/ManyakRus/starter/micro"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// CreateAllFiles - создаёт все файлы в папке nrpc_client
|
||||
func CreateAllFiles(MapAll map[string]*types.Table) error {
|
||||
var err error
|
||||
|
||||
for _, Table1 := range MapAll {
|
||||
//проверка что таблица нормальная
|
||||
err1 := create_files.CheckGoodTable(Table1)
|
||||
if err1 != nil {
|
||||
log.Warn(err1)
|
||||
continue
|
||||
}
|
||||
|
||||
//файлы nrpc_client
|
||||
err = CreateFiles(Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateFiles() table: ", Table1.Name, " error: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
//тестовые файлы nrpc_client
|
||||
if config.Settings.NEED_CREATE_NRPC_CLIENT_TEST == true {
|
||||
err = CreateTestFiles(Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateTestFiles() table: ", Table1.Name, " error: ", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// CreateFiles - создаёт 1 файл в папке nrpc_client
|
||||
func CreateFiles(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()
|
||||
DirTemplatesNRPCClient := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_NRPC_CLIENT + micro.SeparatorFile()
|
||||
DirReadyNRPCClient := DirReady + config.Settings.TEMPLATE_FOLDERNAME_NRPC_CLIENT + micro.SeparatorFile()
|
||||
|
||||
FilenameTemplateNRPCClient := DirTemplatesNRPCClient + "nrpc_client.go_"
|
||||
TableName := strings.ToLower(Table1.Name)
|
||||
DirReadyTable := DirReadyNRPCClient + "nrpc_" + TableName + micro.SeparatorFile()
|
||||
FilenameReadyNRPCClient := DirReadyTable + "nrpc_" + TableName + ".go"
|
||||
|
||||
//создадим каталог
|
||||
ok, err := micro.FileExists(DirReadyTable)
|
||||
if ok == false {
|
||||
err = os.MkdirAll(DirReadyTable, 0777)
|
||||
if err != nil {
|
||||
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
bytes, err := os.ReadFile(FilenameTemplateNRPCClient)
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateNRPCClient, " error: ", err)
|
||||
}
|
||||
TextNRPCClient := string(bytes)
|
||||
|
||||
//заменим имя пакета на новое
|
||||
create_files.ReplacePackageName(TextNRPCClient, DirReadyTable)
|
||||
|
||||
//заменим импорты
|
||||
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
TextNRPCClient = create_files.DeleteTemplateRepositoryImports(TextNRPCClient)
|
||||
|
||||
GRPCProtoURL := create_files.FindProtoURL()
|
||||
TextNRPCClient = create_files.AddImport(TextNRPCClient, GRPCProtoURL)
|
||||
|
||||
NRPCClientURL := create_files.FindNRPCClientURL()
|
||||
TextNRPCClient = create_files.AddImport(TextNRPCClient, NRPCClientURL)
|
||||
|
||||
GRPCConstantsURL := create_files.FindGRPCConstantsURL()
|
||||
TextNRPCClient = create_files.AddImport(TextNRPCClient, GRPCConstantsURL)
|
||||
|
||||
TableURL := create_files.FindModelTableURL(TableName)
|
||||
TextNRPCClient = create_files.AddImport(TextNRPCClient, TableURL)
|
||||
}
|
||||
|
||||
//создание текста
|
||||
ModelName := Table1.NameGo
|
||||
TextNRPCClient = strings.ReplaceAll(TextNRPCClient, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
|
||||
TextNRPCClient = strings.ReplaceAll(TextNRPCClient, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
|
||||
TextNRPCClient = config.Settings.TEXT_MODULE_GENERATED + TextNRPCClient
|
||||
|
||||
if config.Settings.HAS_IS_DELETED == true {
|
||||
TextNRPCClient = DeleteFuncDelete(TextNRPCClient, ModelName, Table1)
|
||||
//TextNRPCClient = DeleteFuncDeleteCtx(TextNRPCClient, ModelName, Table1)
|
||||
TextNRPCClient = DeleteFuncRestore(TextNRPCClient, ModelName, Table1)
|
||||
//TextNRPCClient = DeleteFuncRestoreCtx(TextNRPCClient, ModelName, Table1)
|
||||
}
|
||||
TextNRPCClient = DeleteFuncFind_byExtID(TextNRPCClient, ModelName, Table1)
|
||||
|
||||
//замена импортов на новые URL
|
||||
TextNRPCClient = create_files.ReplaceServiceURLImports(TextNRPCClient)
|
||||
|
||||
//запись файла
|
||||
err = os.WriteFile(FilenameReadyNRPCClient, []byte(TextNRPCClient), constants.FILE_PERMISSIONS)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// CreateTestFiles - создаёт 1 файл в папке nrpc_client
|
||||
func CreateTestFiles(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()
|
||||
DirTemplatesNRPCClient := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_NRPC_CLIENT + micro.SeparatorFile()
|
||||
DirReadyNRPCClient := DirReady + config.Settings.TEMPLATE_FOLDERNAME_NRPC_CLIENT + micro.SeparatorFile()
|
||||
|
||||
FilenameTemplateNRPCClient := DirTemplatesNRPCClient + "nrpc_client_test.go_"
|
||||
TableName := strings.ToLower(Table1.Name)
|
||||
DirReadyTable := DirReadyNRPCClient + "nrpc_" + TableName + micro.SeparatorFile()
|
||||
FilenameReadyNRPCClient := DirReadyTable + "nrpc_" + TableName + "_test.go"
|
||||
|
||||
//создадим каталог
|
||||
ok, err := micro.FileExists(DirReadyTable)
|
||||
if ok == false {
|
||||
err = os.MkdirAll(DirReadyTable, 0777)
|
||||
if err != nil {
|
||||
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
bytes, err := os.ReadFile(FilenameTemplateNRPCClient)
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateNRPCClient, " error: ", err)
|
||||
}
|
||||
TextNRPCClient := string(bytes)
|
||||
|
||||
//заменим имя пакета на новое
|
||||
create_files.ReplacePackageName(TextNRPCClient, DirReadyTable)
|
||||
|
||||
//заменим импорты
|
||||
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
TextNRPCClient = create_files.DeleteTemplateRepositoryImports(TextNRPCClient)
|
||||
|
||||
NRPCClientURL := create_files.FindNRPCClientURL()
|
||||
TextNRPCClient = create_files.AddImport(TextNRPCClient, NRPCClientURL)
|
||||
|
||||
TableURL := create_files.FindModelTableURL(TableName)
|
||||
TextNRPCClient = create_files.AddImport(TextNRPCClient, TableURL)
|
||||
}
|
||||
|
||||
//создание текста
|
||||
ModelName := Table1.NameGo
|
||||
TextNRPCClient = strings.ReplaceAll(TextNRPCClient, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
|
||||
TextNRPCClient = strings.ReplaceAll(TextNRPCClient, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
|
||||
TextNRPCClient = config.Settings.TEXT_MODULE_GENERATED + TextNRPCClient
|
||||
|
||||
if config.Settings.HAS_IS_DELETED == true {
|
||||
TextNRPCClient = DeleteFuncTestDelete(TextNRPCClient, ModelName, Table1)
|
||||
TextNRPCClient = DeleteFuncTestRestore(TextNRPCClient, ModelName, Table1)
|
||||
}
|
||||
TextNRPCClient = DeleteFuncTestFind_byExtID(TextNRPCClient, ModelName, Table1)
|
||||
|
||||
//Postgres_ID_Test = ID Minimum
|
||||
if Table1.IDMinimum != "" {
|
||||
TextFind := "const Postgres_ID_Test = "
|
||||
TextNRPCClient = strings.ReplaceAll(TextNRPCClient, TextFind+"1", TextFind+Table1.IDMinimum)
|
||||
}
|
||||
|
||||
// замена ID на PrimaryKey
|
||||
TextNRPCClient = create_files.ReplacePrimaryKeyID(TextNRPCClient, Table1)
|
||||
|
||||
//SkipNow()
|
||||
TextNRPCClient = create_files.AddSkipNow(TextNRPCClient, Table1)
|
||||
|
||||
//замена импортов на новые URL
|
||||
TextNRPCClient = create_files.ReplaceServiceURLImports(TextNRPCClient)
|
||||
|
||||
//запись файла
|
||||
err = os.WriteFile(FilenameReadyNRPCClient, []byte(TextNRPCClient), constants.FILE_PERMISSIONS)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// DeleteFuncDelete - удаляет функцию Delete()
|
||||
func DeleteFuncDelete(Text, ModelName string, Table1 *types.Table) string {
|
||||
Otvet := Text
|
||||
|
||||
_, ok := Table1.MapColumns["is_deleted"]
|
||||
if ok == true {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
Otvet = create_files.DeleteFuncFromComment(Text, "\n// Delete ")
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// DeleteFuncRestore - удаляет функцию Restore()
|
||||
func DeleteFuncRestore(Text, ModelName string, Table1 *types.Table) string {
|
||||
Otvet := Text
|
||||
|
||||
_, ok := Table1.MapColumns["is_deleted"]
|
||||
if ok == true {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
Otvet = create_files.DeleteFuncFromComment(Text, "\n// Restore ")
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// DeleteFuncDeleteCtx - удаляет функцию Delete_ctx()
|
||||
func DeleteFuncDeleteCtx(Text, ModelName string, Table1 *types.Table) string {
|
||||
Otvet := Text
|
||||
|
||||
_, ok := Table1.MapColumns["is_deleted"]
|
||||
if ok == true {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
Otvet = create_files.DeleteFuncFromComment(Text, "\n// Delete_ctx ")
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// DeleteFuncRestoreCtx - удаляет функцию Restore_ctx()
|
||||
func DeleteFuncRestoreCtx(Text, ModelName string, Table1 *types.Table) string {
|
||||
Otvet := Text
|
||||
|
||||
_, ok := Table1.MapColumns["is_deleted"]
|
||||
if ok == true {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
Otvet = create_files.DeleteFuncFromComment(Text, "\n// Restore_ctx ")
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// DeleteFuncFind_byExtID - удаляет функцию Find_ByExtID()
|
||||
func DeleteFuncFind_byExtID(Text, ModelName string, Table1 *types.Table) string {
|
||||
Otvet := Text
|
||||
|
||||
//если есть обе колонки - ничего не делаем
|
||||
ok := create_files.Has_Column_ExtID_ConnectionID(Table1)
|
||||
if ok == true {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
//
|
||||
Otvet = create_files.DeleteFuncFromComment(Text, "\n// Find_ByExtID ")
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// DeleteFuncTestDelete - удаляет функцию Delete()
|
||||
func DeleteFuncTestDelete(Text, ModelName string, Table1 *types.Table) string {
|
||||
Otvet := Text
|
||||
|
||||
_, ok := Table1.MapColumns["is_deleted"]
|
||||
if ok == true {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
Otvet = create_files.DeleteFuncFromFuncName(Otvet, "TestDelete")
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// DeleteFuncTestRestore - удаляет функцию Restore()
|
||||
func DeleteFuncTestRestore(Text, ModelName string, Table1 *types.Table) string {
|
||||
Otvet := Text
|
||||
|
||||
_, ok := Table1.MapColumns["is_deleted"]
|
||||
if ok == true {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
Otvet = create_files.DeleteFuncFromFuncName(Otvet, "TestRestore")
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// DeleteFuncFind_byExtID - удаляет функцию Find_ByExtID()
|
||||
func DeleteFuncTestFind_byExtID(Text, ModelName string, Table1 *types.Table) string {
|
||||
Otvet := Text
|
||||
|
||||
//если есть обе колонки - ничего не делаем
|
||||
ok := create_files.Has_Column_ExtID_ConnectionID(Table1)
|
||||
if ok == true {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
Otvet = create_files.DeleteFuncFromFuncName(Otvet, "TestFindByExtID")
|
||||
|
||||
return Otvet
|
||||
}
|
@ -0,0 +1 @@
|
||||
package nrpc_client_tables
|
@ -69,7 +69,7 @@ func CreateServerGRPCStarter() error {
|
||||
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
TextGRPCStarter = create_files.DeleteTemplateRepositoryImports(TextGRPCStarter)
|
||||
|
||||
ProtoURL := create_files.FindGRPCProtoURL()
|
||||
ProtoURL := create_files.FindProtoURL()
|
||||
TextGRPCStarter = create_files.AddImport(TextGRPCStarter, ProtoURL)
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ func CreateServerGRPCStarter() error {
|
||||
TextNRPCStarter = create_files.DeleteTemplateRepositoryImports(TextNRPCStarter)
|
||||
|
||||
//Proto URL
|
||||
RepositoryProtoURL := create_files.FindGRPCProtoURL()
|
||||
RepositoryProtoURL := create_files.FindProtoURL()
|
||||
TextNRPCStarter = create_files.AddImport(TextNRPCStarter, RepositoryProtoURL)
|
||||
|
||||
//server grpc URL
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/main_file"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/makefile"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/model"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/nrpc_client"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/nrpc_client_tables"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/server_grpc_starter"
|
||||
"github.com/ManyakRus/crud_generator/internal/create_files/server_nrpc_starter"
|
||||
"github.com/ManyakRus/crud_generator/internal/folders"
|
||||
@ -76,7 +76,7 @@ func StartFillAll() error {
|
||||
}
|
||||
|
||||
//grpc_client
|
||||
err = nrpc_client.CreateAllFiles(MapAll)
|
||||
err = nrpc_client_tables.CreateAllFiles(MapAll)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user