1
0
mirror of https://github.com/ManyakRus/crud_generator.git synced 2024-11-21 05:05:52 +02:00

сделал CopyAllFiles_Exclude_()

This commit is contained in:
Nikitin Aleksandr 2023-11-15 17:59:21 +03:00
parent 6d647c429d
commit 583d4d9579
44 changed files with 702 additions and 114 deletions

2
.gitignore vendored
View File

@ -16,3 +16,5 @@
/bin/ready/pkg/model/ /bin/ready/pkg/model/
/bin/ready/ /bin/ready/
/bin/sync_service/ /bin/sync_service/
/bin/sync_service_test/
/bin/crud_service/

View File

@ -1,7 +1,7 @@
SERVICENAME=crud_generator SERVICENAME=crud_generator
SERVICEURL=github.com/ManyakRus/$(SERVICENAME) SERVICEURL=github.com/ManyakRus/$(SERVICENAME)
FILEMAIN=./internal/main.go FILEMAIN=./cmd/$(SERVICENAME)/main.go
FILEAPP=./bin/$(SERVICENAME) FILEAPP=./bin/$(SERVICENAME)
NEW_REPO=$(SERVICENAME) NEW_REPO=$(SERVICENAME)
@ -11,7 +11,7 @@ run:
clear clear
go build -race -o $(FILEAPP) $(FILEMAIN) go build -race -o $(FILEAPP) $(FILEMAIN)
# cd ./bin && \ # cd ./bin && \
./bin/app_race ./bin/$(SERVICENAME)
mod: mod:
clear clear
go get -u ./... go get -u ./...
@ -21,7 +21,7 @@ mod:
build: build:
clear clear
go build -race -o $(FILEAPP) $(FILEMAIN) go build -race -o $(FILEAPP) $(FILEMAIN)
cd ./cmd && \ cd ./scripts && \
./VersionToFile.py ./VersionToFile.py
lint: lint:

BIN
bin/crud_generator Executable file

Binary file not shown.

View File

@ -1 +1 @@
2023-09-11 13:17:12.998 2023-11-15 12:11:15.838

View File

@ -1 +1 @@
00130 00133

7
bin/templates/.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
.env
/bin/.env
/.idea/
.vscode
/log.txt
cover.out

55
bin/templates/Makefile_ Normal file
View File

@ -0,0 +1,55 @@
SERVICENAME=sync_service
SERVICEURL=github.com/ManyakRus/$(SERVICENAME)
FILEMAIN=./cmd/$(SERVICENAME)/main.go
FILEAPP=./bin/$(SERVICENAME)
NEW_REPO=$(SERVICENAME)
run:
clear
go build -race -o $(FILEAPP) $(FILEMAIN)
# cd ./bin && \
./bin/$(SERVICENAME)
mod:
clear
go get -u ./...
go mod tidy -compat=1.18
go mod vendor
go fmt ./...
build:
clear
go build -race -o $(FILEAPP) $(FILEMAIN)
cd ./scripts && \
./VersionToFile.py
lint:
clear
go fmt ./...
golangci-lint run ./internal/...
golangci-lint run ./pkg/...
gocyclo -over 10 ./internal
gocyclo -over 10 ./pkg
gocritic check ./internal/...
gocritic check ./pkg/...
staticcheck ./internal/...
staticcheck ./pkg/...
run.test:
clear
go fmt ./...
go test -coverprofile cover.out ./internal/v0/app/...
go tool cover -func=cover.out
newrepo:
sed -i 's+$(SERVICEURL)+$(NEW_REPO)+g' go.mod
find -name *.go -not -path "*/vendor/*"|xargs sed -i 's+$(SERVICEURL)+$(NEW_REPO)+g'
graph:
clear
image_packages ./ docs/packages.graphml
conn:
clear
image_connections ./internal docs/connections.graphml $(SERVICENAME)
init:
clear
go mod init gitlab.aescorp.ru/dsp_dev/claim/sync_service
go mod tidy

View File

@ -3,4 +3,4 @@
ADAPT_PATH=./ ADAPT_PATH=./
clear clear
protoc --go_out=${ADAPT_PATH} --nrpc_out=./ --go_opt=paths=import --go-grpc_out=${ADAPT_PATH} --go-grpc_opt=paths=import ${ADAPT_PATH}Sync_service.proto protoc --go_out=${ADAPT_PATH} --nrpc_out=./ --go_opt=paths=import --go-grpc_out=${ADAPT_PATH} --go-grpc_opt=paths=import ${ADAPT_PATH}sync_service.proto

View File

@ -0,0 +1 @@
2023-11-15 12:11:15.838

View File

@ -0,0 +1,29 @@
STAGE="local"
LOG_LEVEL="debug"
#---------------------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=""
#---------------------NATS messages broker settings---------------------
NATS_HOST=""
NATS_PORT=""
NATS_LOGIN=""
NATS_PASSWORD=""

View File

@ -0,0 +1 @@
00133

View File

@ -0,0 +1,7 @@
package constants
const CONNECTION_ID_TEST = 3
const TIMEOUT_DB_SECONDS = 30
const TEXT_RECORD_NOT_FOUND = "record not found"

View File

@ -0,0 +1,106 @@
package grpc_client
import (
"github.com/ManyakRus/starter/contextmain"
"github.com/ManyakRus/starter/log"
"github.com/ManyakRus/starter/stopapp"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/constants"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_proto"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"os"
"strings"
)
type SettingsINI struct {
SYNC_SERVICE_HOST string
SYNC_SERVICE_PORT string
}
var Settings SettingsINI
var Conn *grpc.ClientConn
var Client grpc_proto.SyncServiceClient
func Connect() {
var err error
if Settings.SYNC_SERVICE_HOST == "" {
FillSettings()
}
addr := Settings.SYNC_SERVICE_HOST + ":" + Settings.SYNC_SERVICE_PORT
Conn, err = grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("did not connect: %v", err)
}
log.Info("GRPC client connected. Address: ", addr)
Client = grpc_proto.NewSyncServiceClient(Conn)
}
func FillSettings() {
Settings = SettingsINI{}
Settings.SYNC_SERVICE_HOST = os.Getenv("SYNC_SERVICE_HOST")
Settings.SYNC_SERVICE_PORT = os.Getenv("SYNC_SERVICE_PORT")
if Settings.SYNC_SERVICE_HOST == "" {
log.Panic("Need fill SYNC_SERVICE_HOST ! in OS Environment ")
}
if Settings.SYNC_SERVICE_PORT == "" {
log.Panic("Need fill SYNC_SERVICE_PORT ! in OS Environment ")
}
}
// WaitStop - ожидает отмену глобального контекста
func WaitStop() {
select {
case <-contextmain.GetContext().Done():
log.Warn("Context app is canceled. grpc_connect")
}
// ждём пока отправляемых сейчас сообщений будет =0
stopapp.WaitTotalMessagesSendingNow("sync_service_client")
// закрываем соединение
CloseConnection()
stopapp.GetWaitGroup_Main().Done()
}
// Start - необходимые процедуры для запуска сервера GRPC
func Start() {
Connect()
stopapp.GetWaitGroup_Main().Add(1)
go WaitStop()
}
func CloseConnection() {
err := Conn.Close()
if err != nil {
log.Panic("GRPC client CloseConnection() error: ", err)
} else {
log.Info("GRPC client connection closed")
}
}
// IsRecordNotFound - возвращает true если ошибка = "record not found"
func IsRecordNotFound(err error) bool {
Otvet := false
if err == nil {
return Otvet
}
TextErr := err.Error()
pos1 := strings.Index(TextErr, constants.TEXT_RECORD_NOT_FOUND)
if pos1 >= 0 {
Otvet = true
}
return Otvet
}

View File

@ -0,0 +1,23 @@
package grpc_client
import (
"errors"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/constants"
"testing"
)
func TestIsRecordNotFound(t *testing.T) {
err := errors.New(constants.TEXT_RECORD_NOT_FOUND + " !")
Otvet := IsRecordNotFound(err)
if Otvet != true {
t.Error("TestIsRecordNotFound() error: false")
}
err = errors.New("rpc error: code = Unknown desc = record not found")
Otvet = IsRecordNotFound(err)
if Otvet != true {
t.Error("TestIsRecordNotFound() error: false")
}
}

View File

@ -4,7 +4,7 @@ import (
"encoding/json" "encoding/json"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_proto" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_proto"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/nrpc/nrpc_client" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/nrpc/nrpc_client"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/nrpc/nrpc_client/constants" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/nrpc/grpc_client/constants"
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
"log" "log"
) )

View File

@ -0,0 +1,35 @@
// Package alias -- специальные типы РАПИРы
package alias
// PaymentId -- ID платёжки
type PaymentId int64
// InvoiceId -- ID счёт-фактуры
type InvoiceId int64
// LawsuitId -- ID претензии
type LawsuitId int64
// LawsuitNumber -- номер претензии
type LawsuitNumber string
// ClaimNumber -- Номер дела
type ClaimNumber string
// TrialNumber -- Номер иска
type TrialNumber string
// ContractNumber -- Номер договора
type ContractNumber string
// FrontDate -- специальный тип даты для фронта
type FrontDate string
// FrontTime -- специальный тип даты-времени для фронта
type FrontTime string
// PaymentRegisteredAt -- тип даты времени при регистрации в системе
type PaymentRegisteredAt string
// IsAfterNotify -- признак регистрации документа после уведомления
type IsAfterNotify bool

View File

@ -16,6 +16,7 @@ type SettingsINI struct {
TEMPLATE_FOLDERNAME string TEMPLATE_FOLDERNAME string
TEMPLATE_FOLDERNAME_MODEL string TEMPLATE_FOLDERNAME_MODEL string
TEMPLATE_FOLDERNAME_DB string TEMPLATE_FOLDERNAME_DB string
TEMPLATE_FOLDERNAME_GRPC string
TEMPLATE_FOLDERNAME_GRPC_PROTO string TEMPLATE_FOLDERNAME_GRPC_PROTO string
TEMPLATE_FOLDERNAME_GRPC_SERVER string TEMPLATE_FOLDERNAME_GRPC_SERVER string
TEMPLATE_FOLDERNAME_GRPC_CLIENT string TEMPLATE_FOLDERNAME_GRPC_CLIENT string
@ -138,6 +139,7 @@ func FillSettings() {
Settings.TEMPLATE_FOLDERNAME_MAIN = os.Getenv("TEMPLATE_FOLDERNAME_MAIN") Settings.TEMPLATE_FOLDERNAME_MAIN = os.Getenv("TEMPLATE_FOLDERNAME_MAIN")
Settings.TEMPLATE_REPOSITORY_URL = os.Getenv("TEMPLATE_REPOSITORY_URL") Settings.TEMPLATE_REPOSITORY_URL = os.Getenv("TEMPLATE_REPOSITORY_URL")
Settings.TEMPLATE_FOLDERNAME_GRPC = os.Getenv("TEMPLATE_FOLDERNAME_GRPC")
} }

View File

@ -270,6 +270,24 @@ func FindGRPCServerlURL() string {
return Otvet return Otvet
} }
// FindGRPCClientURL - возвращает URL репозитория с пакетом "client_grpc"
func FindGRPClientURL() string {
Otvet := ""
Otvet = config.Settings.SERVICE_REPOSITORY_URL + "/" + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT
return Otvet
}
// FindGRPCConstantsURL - возвращает URL репозитория с пакетом "client_grpc"
func FindGRPCConstantsURL() string {
Otvet := ""
Otvet = config.Settings.SERVICE_REPOSITORY_URL + "/" + config.Settings.TEMPLATE_FOLDERNAME_GRPC + "/" + "constants"
return Otvet
}
// FindNRPCServerlURL - возвращает URL репозитория с пакетом "server_nrpc" // FindNRPCServerlURL - возвращает URL репозитория с пакетом "server_nrpc"
func FindNRPCServerlURL() string { func FindNRPCServerlURL() string {
Otvet := "" Otvet := ""
@ -279,7 +297,7 @@ func FindNRPCServerlURL() string {
return Otvet return Otvet
} }
// FindProtoURL - возвращает URL репозитория с пакетом "proto" // FindProtoURL - возвращает URL репозитория с файлом .proto
func FindProtoURL() string { func FindProtoURL() string {
Otvet := "" Otvet := ""
@ -288,6 +306,24 @@ func FindProtoURL() string {
return Otvet return Otvet
} }
// FindGRPCProtoURL - возвращает URL репозитория с пакетом "grpc_proto"
func FindGRPCProtoURL() string {
Otvet := ""
Otvet = config.Settings.SERVICE_REPOSITORY_URL + "/" + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + "/" + "grpc_proto"
return Otvet
}
// FindModelTableURL - возвращает URL репозитория model для таблицы TableName
func FindModelTableURL(TableName string) string {
Otvet := ""
Otvet = config.Settings.SERVICE_REPOSITORY_URL + "/" + config.Settings.TEMPLATE_FOLDERNAME_MODEL + "/" + TableName
return Otvet
}
func FindTextDefaultValue(Type_go string) string { func FindTextDefaultValue(Type_go string) string {
var Otvet string var Otvet string
@ -428,3 +464,33 @@ func DeleteTemplateRepositoryImports(Text string) string {
return Otvet return Otvet
} }
// ReplaceServiceURLImports - заменяет URL репозитория шаблона на URL репозитория сервиса
func ReplaceServiceURLImports(Text string) string {
Otvet := Text
if config.Settings.SERVICE_REPOSITORY_URL == "" {
return Otvet
}
if config.Settings.TEMPLATE_REPOSITORY_URL == "" {
return Otvet
}
if config.Settings.USE_DEFAULT_TEMPLATE == false {
return Otvet
}
//
TextFind := "import ("
pos1 := strings.Index(Otvet, TextFind)
if pos1 < 0 {
return Otvet
}
TEMPLATE_REPOSITORY_URL := config.Settings.TEMPLATE_REPOSITORY_URL
SERVICE_REPOSITORY_URL := config.Settings.SERVICE_REPOSITORY_URL
Otvet = strings.ReplaceAll(Otvet, TEMPLATE_REPOSITORY_URL, SERVICE_REPOSITORY_URL)
return Otvet
}

View File

@ -68,6 +68,9 @@ func CreateFileCrudStarter(MapAll map[string]*types.Table) error {
TextCrudStarter = TextCrudStarter + "\n" + TextNRPC TextCrudStarter = TextCrudStarter + "\n" + TextNRPC
} }
//замена импортов на новые URL
TextCrudStarter = create_files.ReplaceServiceURLImports(TextCrudStarter)
//запись файла //запись файла
err = os.WriteFile(FilenameReadyCrudStarter, []byte(TextCrudStarter), constants.FILE_PERMISSIONS) err = os.WriteFile(FilenameReadyCrudStarter, []byte(TextCrudStarter), constants.FILE_PERMISSIONS)
@ -137,7 +140,7 @@ func FindTextImportDB1(Table1 *types.Table) string {
// FindTextImportGRPC1 - возвращает текст импорта GRPC для 1 таблицы // FindTextImportGRPC1 - возвращает текст импорта GRPC для 1 таблицы
func FindTextImportGRPC1(Table1 *types.Table) string { func FindTextImportGRPC1(Table1 *types.Table) string {
GRPC_URL := config.Settings.SERVICE_REPOSITORY_URL + "/" + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO GRPC_URL := config.Settings.SERVICE_REPOSITORY_URL
TableName := strings.ToLower(Table1.Name) TableName := strings.ToLower(Table1.Name)
Otvet := "\n\t\"" + GRPC_URL + "/" + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + "/grpc_" + TableName + `"` Otvet := "\n\t\"" + GRPC_URL + "/" + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + "/grpc_" + TableName + `"`

View File

@ -95,6 +95,9 @@ func CreateFiles(Table1 *types.Table) error {
TextDB = ReplaceText_is_deleted_deleted_at(TextDB, Table1) TextDB = ReplaceText_is_deleted_deleted_at(TextDB, Table1)
TextDB = create_files.DeleteImportModel(TextDB) TextDB = create_files.DeleteImportModel(TextDB)
//замена импортов на новые URL
TextDB = create_files.ReplaceServiceURLImports(TextDB)
//запись файла //запись файла
err = os.WriteFile(FilenameReadyDB, []byte(TextDB), constants.FILE_PERMISSIONS) err = os.WriteFile(FilenameReadyDB, []byte(TextDB), constants.FILE_PERMISSIONS)
@ -157,6 +160,9 @@ func CreateTestFiles(Table1 *types.Table) error {
// замена ID на PrimaryKey // замена ID на PrimaryKey
TextDB = create_files.ReplacePrimaryKeyID(TextDB, Table1) TextDB = create_files.ReplacePrimaryKeyID(TextDB, Table1)
//замена импортов на новые URL
TextDB = create_files.ReplaceServiceURLImports(TextDB)
//запись файла //запись файла
err = os.WriteFile(FilenameReadyDB, []byte(TextDB), constants.FILE_PERMISSIONS) err = os.WriteFile(FilenameReadyDB, []byte(TextDB), constants.FILE_PERMISSIONS)

View File

@ -0,0 +1,66 @@
package generation_code_sh
import (
"github.com/ManyakRus/crud_generator/internal/config"
"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
if config.Settings.USE_DEFAULT_TEMPLATE == false {
return err
}
if config.Settings.NEED_CREATE_GRPC == false {
return err
}
err = CreateFileGenerationCodeSh()
if err != nil {
log.Error("CreateFileGenerationCodeSh() error: ", err)
return err
}
return err
}
// CreateFileGenerationCodeSh - создаёт 1 файл в папке grpc proto
func CreateFileGenerationCodeSh() error {
var err error
if config.Settings.USE_DEFAULT_TEMPLATE == false {
return err
}
//чтение файлов
DirBin := micro.ProgramDir_bin()
DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile()
DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile()
DirTemplatesProto := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + micro.SeparatorFile()
DirReadyProto := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + micro.SeparatorFile()
FilenameReadyProto := DirReadyProto + "generation_code.sh"
FilenameTemplateProto := DirTemplatesProto + "generation_code.sh_"
bytes, err := os.ReadFile(FilenameTemplateProto)
if err != nil {
log.Panic("ReadFile() ", FilenameTemplateProto, " error: ", err)
}
TextGenerationCode := string(bytes)
//создадим папку ready proto
folders.CreateFolder(DirReadyProto)
//replace
TextGenerationCode = strings.ReplaceAll(TextGenerationCode, config.Settings.TEMPLATE_SERVICE_NAME, config.Settings.SERVICE_NAME)
//запись файла
err = os.WriteFile(FilenameReadyProto, []byte(TextGenerationCode), 0777)
return err
}

View File

@ -0,0 +1 @@
package generation_code_sh

View File

@ -51,8 +51,8 @@ func CreateFiles(Table1 *types.Table) error {
DirBin := micro.ProgramDir_bin() DirBin := micro.ProgramDir_bin()
DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile() DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile()
DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile() DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile()
DirTemplatesGRPCClient := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile() DirTemplatesGRPCClient := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile()
DirReadyGRPCClient := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile() DirReadyGRPCClient := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile()
FilenameTemplateGRPCClient := DirTemplatesGRPCClient + "grpc_client.go_" FilenameTemplateGRPCClient := DirTemplatesGRPCClient + "grpc_client.go_"
TableName := strings.ToLower(Table1.Name) TableName := strings.ToLower(Table1.Name)
@ -72,24 +72,48 @@ func CreateFiles(Table1 *types.Table) error {
if err != nil { if err != nil {
log.Panic("ReadFile() ", FilenameTemplateGRPCClient, " error: ", err) log.Panic("ReadFile() ", FilenameTemplateGRPCClient, " error: ", err)
} }
TextDB := string(bytes) TextGRPCClient := string(bytes)
//создание текста //создание текста
ModelName := Table1.NameGo ModelName := Table1.NameGo
TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
TextDB = config.Settings.TEXT_MODULE_GENERATED + TextDB TextGRPCClient = config.Settings.TEXT_MODULE_GENERATED + TextGRPCClient
if config.Settings.HAS_IS_DELETED == true { if config.Settings.HAS_IS_DELETED == true {
TextDB = DeleteFuncDelete(TextDB, ModelName, Table1) TextGRPCClient = DeleteFuncDelete(TextGRPCClient, ModelName, Table1)
//TextDB = DeleteFuncDeleteCtx(TextDB, ModelName, Table1) //TextGRPCClient = DeleteFuncDeleteCtx(TextGRPCClient, ModelName, Table1)
TextDB = DeleteFuncRestore(TextDB, ModelName, Table1) TextGRPCClient = DeleteFuncRestore(TextGRPCClient, ModelName, Table1)
//TextDB = DeleteFuncRestoreCtx(TextDB, ModelName, Table1) //TextGRPCClient = DeleteFuncRestoreCtx(TextGRPCClient, ModelName, Table1)
}
TextGRPCClient = DeleteFuncFind_byExtID(TextGRPCClient, ModelName, Table1)
//замена импортов на новые URL
//TextGRPCClient = create_files.ReplaceServiceURLImports(TextGRPCClient)
if config.Settings.USE_DEFAULT_TEMPLATE == true {
//TextGRPCServer = create_files.ReplaceServiceURLImports(TextGRPCServer)
TextGRPCClient = create_files.DeleteTemplateRepositoryImports(TextGRPCClient)
//proto
RepositoryGRPCProtoURL := create_files.FindGRPCProtoURL()
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)
//constants
RepositoryGRPCConstantsURL := create_files.FindGRPCConstantsURL()
TextGRPCClient = create_files.AddImport(TextGRPCClient, RepositoryGRPCConstantsURL)
} }
TextDB = DeleteFuncFind_byExtID(TextDB, ModelName, Table1)
//запись файла //запись файла
err = os.WriteFile(FilenameReadyGRPCClient, []byte(TextDB), constants.FILE_PERMISSIONS) err = os.WriteFile(FilenameReadyGRPCClient, []byte(TextGRPCClient), constants.FILE_PERMISSIONS)
return err return err
} }
@ -102,8 +126,8 @@ func CreateTestFiles(Table1 *types.Table) error {
DirBin := micro.ProgramDir_bin() DirBin := micro.ProgramDir_bin()
DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile() DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile()
DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile() DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile()
DirTemplatesGRPCClient := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile() DirTemplatesGRPCClient := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile()
DirReadyGRPCClient := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile() DirReadyGRPCClient := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT + micro.SeparatorFile()
FilenameTemplateGRPCClient := DirTemplatesGRPCClient + "grpc_client_test.go_" FilenameTemplateGRPCClient := DirTemplatesGRPCClient + "grpc_client_test.go_"
TableName := strings.ToLower(Table1.Name) TableName := strings.ToLower(Table1.Name)
@ -123,34 +147,37 @@ func CreateTestFiles(Table1 *types.Table) error {
if err != nil { if err != nil {
log.Panic("ReadFile() ", FilenameTemplateGRPCClient, " error: ", err) log.Panic("ReadFile() ", FilenameTemplateGRPCClient, " error: ", err)
} }
TextDB := string(bytes) TextGRPCClient := string(bytes)
//создание текста //создание текста
ModelName := Table1.NameGo ModelName := Table1.NameGo
TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
TextDB = config.Settings.TEXT_MODULE_GENERATED + TextDB TextGRPCClient = config.Settings.TEXT_MODULE_GENERATED + TextGRPCClient
if config.Settings.HAS_IS_DELETED == true { if config.Settings.HAS_IS_DELETED == true {
TextDB = DeleteFuncTestDelete(TextDB, ModelName, Table1) TextGRPCClient = DeleteFuncTestDelete(TextGRPCClient, ModelName, Table1)
TextDB = DeleteFuncTestRestore(TextDB, ModelName, Table1) TextGRPCClient = DeleteFuncTestRestore(TextGRPCClient, ModelName, Table1)
} }
TextDB = DeleteFuncTestFind_byExtID(TextDB, ModelName, Table1) TextGRPCClient = DeleteFuncTestFind_byExtID(TextGRPCClient, ModelName, Table1)
//Postgres_ID_Test = ID Minimum //Postgres_ID_Test = ID Minimum
if Table1.IDMinimum != "" { if Table1.IDMinimum != "" {
TextFind := "const Postgres_ID_Test = " TextFind := "const Postgres_ID_Test = "
TextDB = strings.ReplaceAll(TextDB, TextFind+"1", TextFind+Table1.IDMinimum) TextGRPCClient = strings.ReplaceAll(TextGRPCClient, TextFind+"1", TextFind+Table1.IDMinimum)
} }
// замена ID на PrimaryKey // замена ID на PrimaryKey
TextDB = create_files.ReplacePrimaryKeyID(TextDB, Table1) TextGRPCClient = create_files.ReplacePrimaryKeyID(TextGRPCClient, Table1)
//SkipNow() //SkipNow()
TextDB = create_files.AddSkipNow(TextDB, Table1) TextGRPCClient = create_files.AddSkipNow(TextGRPCClient, Table1)
//замена импортов на новые URL
TextGRPCClient = create_files.ReplaceServiceURLImports(TextGRPCClient)
//запись файла //запись файла
err = os.WriteFile(FilenameReadyGRPCClient, []byte(TextDB), constants.FILE_PERMISSIONS) err = os.WriteFile(FilenameReadyGRPCClient, []byte(TextGRPCClient), constants.FILE_PERMISSIONS)
return err return err
} }

View File

@ -37,7 +37,7 @@ func CreateFileProto(MapAll map[string]*types.Table) error {
DirReadyProto := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + micro.SeparatorFile() DirReadyProto := DirReady + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + micro.SeparatorFile()
FilenameReadyProto := DirReadyProto + config.Settings.SERVICE_NAME + ".proto" FilenameReadyProto := DirReadyProto + config.Settings.SERVICE_NAME + ".proto"
FilenameTemplateProto := DirTemplatesProto + "service.proto" FilenameTemplateProto := DirTemplatesProto + "service.proto_"
bytes, err := os.ReadFile(FilenameTemplateProto) bytes, err := os.ReadFile(FilenameTemplateProto)
if err != nil { if err != nil {
log.Panic("ReadFile() ", FilenameTemplateProto, " error: ", err) log.Panic("ReadFile() ", FilenameTemplateProto, " error: ", err)

View File

@ -62,27 +62,39 @@ func CreateFiles(Table1 *types.Table) error {
if err != nil { if err != nil {
log.Panic("ReadFile() ", FilenameTemplateGRPCServer, " error: ", err) log.Panic("ReadFile() ", FilenameTemplateGRPCServer, " error: ", err)
} }
TextDB := string(bytes) TextGRPCServer := string(bytes)
//создание текста //создание текста
ModelName := Table1.NameGo ModelName := Table1.NameGo
TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) TextGRPCServer = strings.ReplaceAll(TextGRPCServer, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) TextGRPCServer = strings.ReplaceAll(TextGRPCServer, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
TextDB = config.Settings.TEXT_MODULE_GENERATED + TextDB TextGRPCServer = config.Settings.TEXT_MODULE_GENERATED + TextGRPCServer
if config.Settings.USE_DEFAULT_TEMPLATE == true { if config.Settings.USE_DEFAULT_TEMPLATE == true {
if config.Settings.HAS_IS_DELETED == true { if config.Settings.HAS_IS_DELETED == true {
TextDB = DeleteFuncDelete(TextDB, ModelName, Table1) TextGRPCServer = DeleteFuncDelete(TextGRPCServer, ModelName, Table1)
TextDB = DeleteFuncDeleteCtx(TextDB, ModelName, Table1) TextGRPCServer = DeleteFuncDeleteCtx(TextGRPCServer, ModelName, Table1)
TextDB = DeleteFuncRestore(TextDB, ModelName, Table1) TextGRPCServer = DeleteFuncRestore(TextGRPCServer, ModelName, Table1)
TextDB = DeleteFuncRestoreCtx(TextDB, ModelName, Table1) TextGRPCServer = DeleteFuncRestoreCtx(TextGRPCServer, ModelName, Table1)
} }
TextDB = DeleteFuncFind_byExtID(TextDB, ModelName, Table1) TextGRPCServer = DeleteFuncFind_byExtID(TextGRPCServer, ModelName, Table1)
TextDB = ConvertID(TextDB, Table1) TextGRPCServer = ConvertID(TextGRPCServer, Table1)
//замена импортов на новые URL
//TextGRPCServer = create_files.ReplaceServiceURLImports(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)
} }
//запись файла //запись файла
err = os.WriteFile(FilenameReadyGRPCServer, []byte(TextDB), constants.FILE_PERMISSIONS) err = os.WriteFile(FilenameReadyGRPCServer, []byte(TextGRPCServer), constants.FILE_PERMISSIONS)
return err return err
} }
@ -107,34 +119,37 @@ func CreateTestFiles(Table1 *types.Table) error {
if err != nil { if err != nil {
log.Panic("ReadFile() ", FilenameTemplateGRPCServer, " error: ", err) log.Panic("ReadFile() ", FilenameTemplateGRPCServer, " error: ", err)
} }
TextDB := string(bytes) TextGRPCServer := string(bytes)
//создание текста //создание текста
ModelName := Table1.NameGo ModelName := Table1.NameGo
TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) TextGRPCServer = strings.ReplaceAll(TextGRPCServer, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) TextGRPCServer = strings.ReplaceAll(TextGRPCServer, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
TextDB = config.Settings.TEXT_MODULE_GENERATED + TextDB TextGRPCServer = config.Settings.TEXT_MODULE_GENERATED + TextGRPCServer
if config.Settings.HAS_IS_DELETED == true { if config.Settings.HAS_IS_DELETED == true {
TextDB = DeleteFuncTestDelete(TextDB, ModelName, Table1) TextGRPCServer = DeleteFuncTestDelete(TextGRPCServer, ModelName, Table1)
TextDB = DeleteFuncTestRestore(TextDB, ModelName, Table1) TextGRPCServer = DeleteFuncTestRestore(TextGRPCServer, ModelName, Table1)
} }
TextDB = DeleteFuncTestFind_byExtID(TextDB, ModelName, Table1) TextGRPCServer = DeleteFuncTestFind_byExtID(TextGRPCServer, ModelName, Table1)
//Postgres_ID_Test = ID Minimum //Postgres_ID_Test = ID Minimum
if Table1.IDMinimum != "" { if Table1.IDMinimum != "" {
TextFind := "const " + ModelName + "_ID_Test = " TextFind := "const " + ModelName + "_ID_Test = "
TextDB = strings.ReplaceAll(TextDB, TextFind+"1", TextFind+Table1.IDMinimum) TextGRPCServer = strings.ReplaceAll(TextGRPCServer, TextFind+"1", TextFind+Table1.IDMinimum)
} }
// замена ID на PrimaryKey // замена ID на PrimaryKey
TextDB = create_files.ReplacePrimaryKeyID(TextDB, Table1) TextGRPCServer = create_files.ReplacePrimaryKeyID(TextGRPCServer, Table1)
//SkipNow() //SkipNow()
TextDB = create_files.AddSkipNow(TextDB, Table1) TextGRPCServer = create_files.AddSkipNow(TextGRPCServer, Table1)
//замена импортов на новые URL
TextGRPCServer = create_files.ReplaceServiceURLImports(TextGRPCServer)
//запись файла //запись файла
err = os.WriteFile(FilenameReadyGRPCServer, []byte(TextDB), constants.FILE_PERMISSIONS) err = os.WriteFile(FilenameReadyGRPCServer, []byte(TextGRPCServer), constants.FILE_PERMISSIONS)
return err return err
} }

View File

@ -64,6 +64,9 @@ func CreateFileMain() error {
} }
} }
//замена импортов на новые URL
TextMain = create_files.ReplaceServiceURLImports(TextMain)
//запись файла //запись файла
err = os.WriteFile(FilenameReadyMain, []byte(TextMain), constants.FILE_PERMISSIONS) err = os.WriteFile(FilenameReadyMain, []byte(TextMain), constants.FILE_PERMISSIONS)

View File

@ -0,0 +1,59 @@
package makefile
import (
"github.com/ManyakRus/crud_generator/internal/config"
"github.com/ManyakRus/crud_generator/internal/constants"
"github.com/ManyakRus/crud_generator/internal/folders"
"github.com/ManyakRus/starter/log"
"github.com/ManyakRus/starter/micro"
"os"
"strings"
)
// CreateAllFiles - создаёт файл makefile в корне проекта
func CreateAllFiles() error {
var err error
err = CreateMakefile()
if err != nil {
log.Error("CreateMakefile() error: ", err)
return err
}
return err
}
// CreateMakefile - создаёт 1 файл в папке grpc
func CreateMakefile() error {
var err error
if config.Settings.USE_DEFAULT_TEMPLATE == false {
return err
}
//чтение файлов
DirBin := micro.ProgramDir_bin()
DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile()
DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile()
DirTemplatesMakefile := DirTemplates
DirReadyMakefile := DirReady
FilenameReadyMakefile := DirReadyMakefile + "Makefile"
FilenameTemplateMakefile := DirTemplatesMakefile + "Makefile_"
bytes, err := os.ReadFile(FilenameTemplateMakefile)
if err != nil {
log.Panic("ReadFile() ", FilenameTemplateMakefile, " error: ", err)
}
TextMakefile := string(bytes)
//создадим папку ready
folders.CreateFolder(DirReadyMakefile)
//ReplaceAll
TextMakefile = strings.ReplaceAll(TextMakefile, config.Settings.TEMPLATE_SERVICE_NAME, strings.ToLower(config.Settings.SERVICE_NAME))
//запись файла
err = os.WriteFile(FilenameReadyMakefile, []byte(TextMakefile), constants.FILE_PERMISSIONS)
return err
}

View File

@ -0,0 +1 @@
package makefile

View File

@ -104,6 +104,9 @@ func CreateFilesModel_struct(Table1 *types.Table, DirTemplatesModel, DirReadyMod
TextModel = create_files.CheckAndAddImportTime_FromText(TextModel) TextModel = create_files.CheckAndAddImportTime_FromText(TextModel)
TextModel = create_files.DeleteImportModel(TextModel) TextModel = create_files.DeleteImportModel(TextModel)
//замена импортов на новые URL
TextModel = create_files.ReplaceServiceURLImports(TextModel)
//запись файла //запись файла
err = os.WriteFile(FilenameReadyModel, []byte(TextModel), constants.FILE_PERMISSIONS) err = os.WriteFile(FilenameReadyModel, []byte(TextModel), constants.FILE_PERMISSIONS)
@ -143,6 +146,9 @@ func CreateFilesModel_crud(Table1 *types.Table, DirTemplatesModel, DirReadyModel
TextModel = create_files.CheckAndAddImportTime_FromText(TextModel) TextModel = create_files.CheckAndAddImportTime_FromText(TextModel)
TextModel = create_files.DeleteImportModel(TextModel) TextModel = create_files.DeleteImportModel(TextModel)
//замена импортов на новые URL
TextModel = create_files.ReplaceServiceURLImports(TextModel)
//запись файла //запись файла
err = os.WriteFile(FilenameReadyModel, []byte(TextModel), constants.FILE_PERMISSIONS) err = os.WriteFile(FilenameReadyModel, []byte(TextModel), constants.FILE_PERMISSIONS)

View File

@ -71,24 +71,27 @@ func CreateFiles(Table1 *types.Table) error {
if err != nil { if err != nil {
log.Panic("ReadFile() ", FilenameTemplateNRPCClient, " error: ", err) log.Panic("ReadFile() ", FilenameTemplateNRPCClient, " error: ", err)
} }
TextDB := string(bytes) TextNRPCClient := string(bytes)
//создание текста //создание текста
ModelName := Table1.NameGo ModelName := Table1.NameGo
TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) TextNRPCClient = strings.ReplaceAll(TextNRPCClient, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) TextNRPCClient = strings.ReplaceAll(TextNRPCClient, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
TextDB = config.Settings.TEXT_MODULE_GENERATED + TextDB TextNRPCClient = config.Settings.TEXT_MODULE_GENERATED + TextNRPCClient
if config.Settings.HAS_IS_DELETED == true { if config.Settings.HAS_IS_DELETED == true {
TextDB = DeleteFuncDelete(TextDB, ModelName, Table1) TextNRPCClient = DeleteFuncDelete(TextNRPCClient, ModelName, Table1)
//TextDB = DeleteFuncDeleteCtx(TextDB, ModelName, Table1) //TextNRPCClient = DeleteFuncDeleteCtx(TextNRPCClient, ModelName, Table1)
TextDB = DeleteFuncRestore(TextDB, ModelName, Table1) TextNRPCClient = DeleteFuncRestore(TextNRPCClient, ModelName, Table1)
//TextDB = DeleteFuncRestoreCtx(TextDB, ModelName, Table1) //TextNRPCClient = DeleteFuncRestoreCtx(TextNRPCClient, ModelName, Table1)
} }
TextDB = DeleteFuncFind_byExtID(TextDB, ModelName, Table1) TextNRPCClient = DeleteFuncFind_byExtID(TextNRPCClient, ModelName, Table1)
//замена импортов на новые URL
TextNRPCClient = create_files.ReplaceServiceURLImports(TextNRPCClient)
//запись файла //запись файла
err = os.WriteFile(FilenameReadyNRPCClient, []byte(TextDB), constants.FILE_PERMISSIONS) err = os.WriteFile(FilenameReadyNRPCClient, []byte(TextNRPCClient), constants.FILE_PERMISSIONS)
return err return err
} }
@ -122,34 +125,37 @@ func CreateTestFiles(Table1 *types.Table) error {
if err != nil { if err != nil {
log.Panic("ReadFile() ", FilenameTemplateNRPCClient, " error: ", err) log.Panic("ReadFile() ", FilenameTemplateNRPCClient, " error: ", err)
} }
TextDB := string(bytes) TextNRPCClient := string(bytes)
//создание текста //создание текста
ModelName := Table1.NameGo ModelName := Table1.NameGo
TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_MODEL, ModelName) TextNRPCClient = strings.ReplaceAll(TextNRPCClient, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name) TextNRPCClient = strings.ReplaceAll(TextNRPCClient, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
TextDB = config.Settings.TEXT_MODULE_GENERATED + TextDB TextNRPCClient = config.Settings.TEXT_MODULE_GENERATED + TextNRPCClient
if config.Settings.HAS_IS_DELETED == true { if config.Settings.HAS_IS_DELETED == true {
TextDB = DeleteFuncTestDelete(TextDB, ModelName, Table1) TextNRPCClient = DeleteFuncTestDelete(TextNRPCClient, ModelName, Table1)
TextDB = DeleteFuncTestRestore(TextDB, ModelName, Table1) TextNRPCClient = DeleteFuncTestRestore(TextNRPCClient, ModelName, Table1)
} }
TextDB = DeleteFuncTestFind_byExtID(TextDB, ModelName, Table1) TextNRPCClient = DeleteFuncTestFind_byExtID(TextNRPCClient, ModelName, Table1)
//Postgres_ID_Test = ID Minimum //Postgres_ID_Test = ID Minimum
if Table1.IDMinimum != "" { if Table1.IDMinimum != "" {
TextFind := "const Postgres_ID_Test = " TextFind := "const Postgres_ID_Test = "
TextDB = strings.ReplaceAll(TextDB, TextFind+"1", TextFind+Table1.IDMinimum) TextNRPCClient = strings.ReplaceAll(TextNRPCClient, TextFind+"1", TextFind+Table1.IDMinimum)
} }
// замена ID на PrimaryKey // замена ID на PrimaryKey
TextDB = create_files.ReplacePrimaryKeyID(TextDB, Table1) TextNRPCClient = create_files.ReplacePrimaryKeyID(TextNRPCClient, Table1)
//SkipNow() //SkipNow()
TextDB = create_files.AddSkipNow(TextDB, Table1) TextNRPCClient = create_files.AddSkipNow(TextNRPCClient, Table1)
//замена импортов на новые URL
TextNRPCClient = create_files.ReplaceServiceURLImports(TextNRPCClient)
//запись файла //запись файла
err = os.WriteFile(FilenameReadyNRPCClient, []byte(TextDB), constants.FILE_PERMISSIONS) err = os.WriteFile(FilenameReadyNRPCClient, []byte(TextNRPCClient), constants.FILE_PERMISSIONS)
return err return err
} }

View File

@ -51,6 +51,8 @@ func CreateServerGRPCStarter() error {
folders.CreateFolder(DirReadyServerGRPC) folders.CreateFolder(DirReadyServerGRPC)
if config.Settings.USE_DEFAULT_TEMPLATE == true { if config.Settings.USE_DEFAULT_TEMPLATE == true {
TextGRPCStarter = create_files.DeleteTemplateRepositoryImports(TextGRPCStarter)
//заменим имя сервиса на новое //заменим имя сервиса на новое
ServiceNameTemplate := config.Settings.TEMPLATE_SERVICE_NAME ServiceNameTemplate := config.Settings.TEMPLATE_SERVICE_NAME
ServiceName := config.Settings.SERVICE_NAME ServiceName := config.Settings.SERVICE_NAME
@ -63,8 +65,8 @@ func CreateServerGRPCStarter() error {
TextGRPCStarter = strings.ReplaceAll(TextGRPCStarter, ServiceNameTemplate, ServiceName) TextGRPCStarter = strings.ReplaceAll(TextGRPCStarter, ServiceNameTemplate, ServiceName)
TextGRPCStarter = strings.ReplaceAll(TextGRPCStarter, micro.StringFromUpperCase(ServiceNameTemplate), micro.StringFromUpperCase(ServiceName)) TextGRPCStarter = strings.ReplaceAll(TextGRPCStarter, micro.StringFromUpperCase(ServiceNameTemplate), micro.StringFromUpperCase(ServiceName))
TextGRPCStarter = create_files.DeleteTemplateRepositoryImports(TextGRPCStarter) //proto
ProtoURL := create_files.FindProtoURL() + "/grpc_proto" ProtoURL := create_files.FindGRPCProtoURL()
TextGRPCStarter = create_files.AddImport(TextGRPCStarter, ProtoURL) TextGRPCStarter = create_files.AddImport(TextGRPCStarter, ProtoURL)
} }

View File

@ -8,7 +8,6 @@ import (
"github.com/ManyakRus/starter/log" "github.com/ManyakRus/starter/log"
"github.com/ManyakRus/starter/micro" "github.com/ManyakRus/starter/micro"
"os" "os"
"strings"
) )
// CreateAllFiles - создаёт все файлы в папке grpc proto // CreateAllFiles - создаёт все файлы в папке grpc proto
@ -52,18 +51,26 @@ func CreateServerGRPCStarter() error {
if config.Settings.USE_DEFAULT_TEMPLATE == true { if config.Settings.USE_DEFAULT_TEMPLATE == true {
//заменим имя сервиса на новое //заменим имя сервиса на новое
ServiceNameTemplate := config.Settings.TEMPLATE_SERVICE_NAME //ServiceNameTemplate := config.Settings.TEMPLATE_SERVICE_NAME
ServiceName := config.Settings.SERVICE_NAME //ServiceName := config.Settings.SERVICE_NAME
TextNRPCStarter = strings.ReplaceAll(TextNRPCStarter, ServiceNameTemplate, ServiceName) //TextNRPCStarter = strings.ReplaceAll(TextNRPCStarter, ServiceNameTemplate, ServiceName)
TextNRPCStarter = strings.ReplaceAll(TextNRPCStarter, micro.StringFromUpperCase(ServiceNameTemplate), micro.StringFromUpperCase(ServiceName)) //TextNRPCStarter = strings.ReplaceAll(TextNRPCStarter, micro.StringFromUpperCase(ServiceNameTemplate), micro.StringFromUpperCase(ServiceName))
TextNRPCStarter = create_files.DeleteTemplateRepositoryImports(TextNRPCStarter) TextNRPCStarter = create_files.DeleteTemplateRepositoryImports(TextNRPCStarter)
ProtoURL := create_files.FindProtoURL() + "/grpc_proto" //ProtoURL := create_files.FindProtoURL() + "/grpc_proto"
TextNRPCStarter = create_files.AddImport(TextNRPCStarter, ProtoURL) //TextNRPCStarter = create_files.AddImport(TextNRPCStarter, ProtoURL)
//
//GRPCServer_URL := create_files.FindGRPCServerlURL()
//TextNRPCStarter = create_files.AddImport(TextNRPCStarter, GRPCServer_URL)
GRPCServer_URL := create_files.FindGRPCServerlURL() //Proto URL
TextNRPCStarter = create_files.AddImport(TextNRPCStarter, GRPCServer_URL) RepositoryProtoURL := create_files.FindGRPCProtoURL()
TextNRPCStarter = create_files.AddImport(TextNRPCStarter, RepositoryProtoURL)
//server grpc URL
RepositoryServerGRPCURL := create_files.FindGRPCServerlURL()
TextNRPCStarter = create_files.AddImport(TextNRPCStarter, RepositoryServerGRPCURL)
} }
//запись файла //запись файла

View File

@ -158,16 +158,16 @@ func CreateAllFolders() {
log.Info("CreateFolder_err() ", Filename) log.Info("CreateFolder_err() ", Filename)
} }
//grpc client ////grpc client
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT //Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT
ok, err = micro.FileExists(Filename) //ok, err = micro.FileExists(Filename)
if ok == false || err != nil { //if ok == false || err != nil {
err = CreateFolder_err(Filename, 0777) // err = CreateFolder_err(Filename, 0777)
if err != nil { // if err != nil {
log.Panic("CreateFolder_err() ", Filename, " error: ", err) // log.Panic("CreateFolder_err() ", Filename, " error: ", err)
} // }
log.Info("CreateFolder_err() ", Filename) // log.Info("CreateFolder_err() ", Filename)
} //}
//grpc_proto //grpc_proto
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + micro.SeparatorFile() + "grpc_proto" Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_GRPC_PROTO + micro.SeparatorFile() + "grpc_proto"

View File

@ -4,10 +4,12 @@ import (
"github.com/ManyakRus/crud_generator/internal/config" "github.com/ManyakRus/crud_generator/internal/config"
"github.com/ManyakRus/crud_generator/internal/create_files/crud_starter" "github.com/ManyakRus/crud_generator/internal/create_files/crud_starter"
"github.com/ManyakRus/crud_generator/internal/create_files/db" "github.com/ManyakRus/crud_generator/internal/create_files/db"
"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"
"github.com/ManyakRus/crud_generator/internal/create_files/grpc_proto" "github.com/ManyakRus/crud_generator/internal/create_files/grpc_proto"
"github.com/ManyakRus/crud_generator/internal/create_files/grpc_server" "github.com/ManyakRus/crud_generator/internal/create_files/grpc_server"
"github.com/ManyakRus/crud_generator/internal/create_files/main_file" "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/model"
"github.com/ManyakRus/crud_generator/internal/create_files/nrpc_client" "github.com/ManyakRus/crud_generator/internal/create_files/nrpc_client"
"github.com/ManyakRus/crud_generator/internal/create_files/server_grpc_starter" "github.com/ManyakRus/crud_generator/internal/create_files/server_grpc_starter"
@ -101,20 +103,17 @@ func StartFillAll() error {
return err return err
} }
//makefile
err = makefile.CreateAllFiles()
if err != nil {
return err
}
//generation_code.sh
err = generation_code_sh.CreateAllFiles()
if err != nil {
return err
}
return err return err
} }
//// MassFromMapColumns - возвращает Slice из Map
//func MassFromMapColumns(MapColumns map[string]types.Column) []types.Column {
// Otvet := make([]types.Column, 0)
//
// for _, v := range MapColumns {
// Otvet = append(Otvet, v)
// }
//
// sort.Slice(Otvet[:], func(i, j int) bool {
// return Otvet[i].OrderNumber < Otvet[j].OrderNumber
// })
//
// return Otvet
//}

52
scripts/VersionToFile.py Executable file
View File

@ -0,0 +1,52 @@
#!/usr/bin/python3
# Python script to create an empty file
# with current date as name.
# importing datetime module
from datetime import datetime
import os
# datetime.datetime.now() to get
# current date as filename.
# TimeNow = datetime.datetime.now()
FILESUBVERSION="../bin/subversion.txt"
FILEDATE="../bin/date.txt"
# create empty file
def create_file():
fmt = "%Y-%m-%d %H:%M:%S.%f"
str1 = datetime.utcnow().strftime(fmt)[:-3]
# Function creates an empty file
# %d - date, %B - month, %Y - Year
with open(FILEDATE, "w") as file:
file.write(str1)
file.close()
def set_version():
filename=FILESUBVERSION
build=0
mode = 'r' if os.path.exists(filename) else 'w+'
with open(filename, encoding="utf8", mode=mode) as file_in:
_str_build = file_in.read()
file_in.close()
try:
build = int(_str_build)
except ValueError as err:
print("Build.__setVers(): при конвертировании строки в число, err=", err)
finally:
pass
build += 1
str_build = str(build)
while len(str_build) < 5:
str_build = "0" + str_build
print("Build.set_version(): new build=", str_build)
with open(filename, "w", encoding="utf8") as file_in:
file_in.write(str_build)
file_in.close()
# Driver Code
create_file()
set_version()

View File

@ -0,0 +1 @@
v0