mirror of
https://github.com/ManyakRus/crud_generator.git
synced 2025-01-03 01:22:21 +02:00
сделал crud_starter
This commit is contained in:
parent
d722250106
commit
b8eb2ad0ab
95
bin/templates/crud_starter/crud_starter.go_
Normal file
95
bin/templates/crud_starter/crud_starter.go_
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
package crud_starter
|
||||||
|
|
||||||
|
import (
|
||||||
|
model "gitlab.aescorp.ru/dsp_dev/claim/common/object_model"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/db/db_connections"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/db/db_employees"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/db/db_files"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/db/db_lawsuit_status_states"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/db/db_lawsuit_status_types"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/db/db_lawsuits"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/db/db_message_attachements"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/db/db_message_send_statuses"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/db/db_message_types"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/db/db_messages"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/db/db_organization_casebook"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/db/db_organizations"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/grpc/grpc_client/grpc_connections"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/grpc/grpc_client/grpc_employees"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/grpc/grpc_client/grpc_files"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/grpc/grpc_client/grpc_lawsuit_status_states"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/grpc/grpc_client/grpc_lawsuit_status_types"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/grpc/grpc_client/grpc_lawsuits"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/grpc/grpc_client/grpc_message_attachements"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/grpc/grpc_client/grpc_message_send_statuses"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/grpc/grpc_client/grpc_message_types"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/grpc/grpc_client/grpc_messages"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/grpc/grpc_client/grpc_organization_casebook"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/grpc/grpc_client/grpc_organizations"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/nrpc/nrpc_client/nrpc_connections"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/nrpc/nrpc_client/nrpc_employees"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/nrpc/nrpc_client/nrpc_files"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/nrpc/nrpc_client/nrpc_lawsuit_status_states"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/nrpc/nrpc_client/nrpc_lawsuit_status_types"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/nrpc/nrpc_client/nrpc_lawsuits"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/nrpc/nrpc_client/nrpc_message_attachements"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/nrpc/nrpc_client/nrpc_message_send_statuses"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/nrpc/nrpc_client/nrpc_message_types"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/nrpc/nrpc_client/nrpc_messages"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/nrpc/nrpc_client/nrpc_organization_casebook"
|
||||||
|
"gitlab.aescorp.ru/dsp_dev/claim/common/object_model/pkg/nrpc/nrpc_client/nrpc_organizations"
|
||||||
|
)
|
||||||
|
|
||||||
|
// InitCrudTransport_DB - заполняет объекты crud для работы с БД напрямую
|
||||||
|
func InitCrudTransport_DB() {
|
||||||
|
|
||||||
|
model.Connection{}.SetCrudInterface(db_connections.Crud_DB{})
|
||||||
|
model.Employee{}.SetCrudInterface(db_employees.Crud_DB{})
|
||||||
|
model.File{}.SetCrudInterface(db_files.Crud_DB{})
|
||||||
|
model.LawsuitStatusState{}.SetCrudInterface(db_lawsuit_status_states.Crud_DB{})
|
||||||
|
model.LawsuitStatusType{}.SetCrudInterface(db_lawsuit_status_types.Crud_DB{})
|
||||||
|
model.Lawsuit{}.SetCrudInterface(db_lawsuits.Crud_DB{})
|
||||||
|
model.MessageAttachement{}.SetCrudInterface(db_message_attachements.Crud_DB{})
|
||||||
|
model.MessageSendStatus{}.SetCrudInterface(db_message_send_statuses.Crud_DB{})
|
||||||
|
model.MessageType{}.SetCrudInterface(db_message_types.Crud_DB{})
|
||||||
|
model.Message{}.SetCrudInterface(db_messages.Crud_DB{})
|
||||||
|
model.OrganizationCasebook{}.SetCrudInterface(db_organization_casebook.Crud_DB{})
|
||||||
|
model.Organization{}.SetCrudInterface(db_organizations.Crud_DB{})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// InitCrudTransport_GRPC - заполняет объекты crud для работы с БД напрямую
|
||||||
|
func InitCrudTransport_GRPC() {
|
||||||
|
|
||||||
|
model.Connection{}.SetCrudInterface(grpc_connections.Crud_GRPC{})
|
||||||
|
model.Employee{}.SetCrudInterface(grpc_employees.Crud_GRPC{})
|
||||||
|
model.File{}.SetCrudInterface(grpc_files.Crud_GRPC{})
|
||||||
|
model.LawsuitStatusState{}.SetCrudInterface(grpc_lawsuit_status_states.Crud_GRPC{})
|
||||||
|
model.LawsuitStatusType{}.SetCrudInterface(grpc_lawsuit_status_types.Crud_GRPC{})
|
||||||
|
model.Lawsuit{}.SetCrudInterface(grpc_lawsuits.Crud_GRPC{})
|
||||||
|
model.MessageAttachement{}.SetCrudInterface(grpc_message_attachements.Crud_GRPC{})
|
||||||
|
model.MessageSendStatus{}.SetCrudInterface(grpc_message_send_statuses.Crud_GRPC{})
|
||||||
|
model.MessageType{}.SetCrudInterface(grpc_message_types.Crud_GRPC{})
|
||||||
|
model.Message{}.SetCrudInterface(grpc_messages.Crud_GRPC{})
|
||||||
|
model.OrganizationCasebook{}.SetCrudInterface(grpc_organization_casebook.Crud_GRPC{})
|
||||||
|
model.Organization{}.SetCrudInterface(grpc_organizations.Crud_GRPC{})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// InitCrudTransport_NRPC - заполняет объекты crud для работы с БД напрямую
|
||||||
|
func InitCrudTransport_NRPC() {
|
||||||
|
|
||||||
|
model.Connection{}.SetCrudInterface(nrpc_connections.Crud_NRPC{})
|
||||||
|
model.Employee{}.SetCrudInterface(nrpc_employees.Crud_NRPC{})
|
||||||
|
model.File{}.SetCrudInterface(nrpc_files.Crud_NRPC{})
|
||||||
|
model.LawsuitStatusState{}.SetCrudInterface(nrpc_lawsuit_status_states.Crud_NRPC{})
|
||||||
|
model.LawsuitStatusType{}.SetCrudInterface(nrpc_lawsuit_status_types.Crud_NRPC{})
|
||||||
|
model.Lawsuit{}.SetCrudInterface(nrpc_lawsuits.Crud_NRPC{})
|
||||||
|
model.MessageAttachement{}.SetCrudInterface(nrpc_message_attachements.Crud_NRPC{})
|
||||||
|
model.MessageSendStatus{}.SetCrudInterface(nrpc_message_send_statuses.Crud_NRPC{})
|
||||||
|
model.MessageType{}.SetCrudInterface(nrpc_message_types.Crud_NRPC{})
|
||||||
|
model.Message{}.SetCrudInterface(nrpc_messages.Crud_NRPC{})
|
||||||
|
model.OrganizationCasebook{}.SetCrudInterface(nrpc_organization_casebook.Crud_NRPC{})
|
||||||
|
model.Organization{}.SetCrudInterface(nrpc_organizations.Crud_NRPC{})
|
||||||
|
|
||||||
|
}
|
@ -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
|
||||||
|
@ -11,25 +11,28 @@ var Settings SettingsINI
|
|||||||
|
|
||||||
// SettingsINI - структура для хранения всех нужных переменных окружения
|
// SettingsINI - структура для хранения всех нужных переменных окружения
|
||||||
type SettingsINI struct {
|
type SettingsINI struct {
|
||||||
INCLUDE_TABLES string
|
INCLUDE_TABLES string
|
||||||
EXCLUDE_TABLES string
|
EXCLUDE_TABLES string
|
||||||
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 string
|
||||||
TEMPLATE_FOLDERNAME_GRPC_SERVER string
|
TEMPLATE_FOLDERNAME_GRPC_SERVER string
|
||||||
TEMPLATE_FOLDERNAME_GRPC_CLIENT string
|
TEMPLATE_FOLDERNAME_GRPC_CLIENT string
|
||||||
TEMPLATE_FOLDERNAME_NRPC string
|
TEMPLATE_FOLDERNAME_NRPC string
|
||||||
TEMPLATE_FOLDERNAME_NRPC_SERVER string
|
TEMPLATE_FOLDERNAME_NRPC_SERVER string
|
||||||
TEMPLATE_FOLDERNAME_NRPC_CLIENT string
|
TEMPLATE_FOLDERNAME_NRPC_CLIENT string
|
||||||
TEMPLATE_SERVICE_NAME string
|
TEMPLATE_SERVICE_NAME string
|
||||||
NEED_CRUD bool
|
TEMPLATE_FOLDERNAME_CRUD_STARTER string
|
||||||
NEED_GRPC bool
|
NEED_CRUD bool
|
||||||
NEED_NRPC bool
|
NEED_GRPC bool
|
||||||
SERVICE_NAME string
|
NEED_NRPC bool
|
||||||
TEXT_TEMPLATE_MODEL string
|
SERVICE_NAME string
|
||||||
TEXT_TEMPLATE_TABLENAME string
|
SERVICE_REPOSITORY_URL string
|
||||||
HAS_IS_DELETED bool
|
TEXT_TEMPLATE_MODEL string
|
||||||
|
TEXT_TEMPLATE_TABLENAME string
|
||||||
|
HAS_IS_DELETED bool
|
||||||
|
NEED_MODEL_ONE_FOLDER bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// FillSettings загружает переменные окружения в структуру из переменных окружения
|
// FillSettings загружает переменные окружения в структуру из переменных окружения
|
||||||
@ -49,6 +52,9 @@ func FillSettings() {
|
|||||||
Settings.TEXT_TEMPLATE_MODEL = os.Getenv("TEXT_TEMPLATE_MODEL")
|
Settings.TEXT_TEMPLATE_MODEL = os.Getenv("TEXT_TEMPLATE_MODEL")
|
||||||
Settings.TEXT_TEMPLATE_TABLENAME = os.Getenv("TEXT_TEMPLATE_TABLENAME")
|
Settings.TEXT_TEMPLATE_TABLENAME = os.Getenv("TEXT_TEMPLATE_TABLENAME")
|
||||||
Settings.TEMPLATE_SERVICE_NAME = os.Getenv("TEMPLATE_SERVICE_NAME")
|
Settings.TEMPLATE_SERVICE_NAME = os.Getenv("TEMPLATE_SERVICE_NAME")
|
||||||
|
Settings.TEMPLATE_FOLDERNAME_CRUD_STARTER = os.Getenv("TEMPLATE_FOLDERNAME_CRUD_STARTER")
|
||||||
|
Settings.SERVICE_REPOSITORY_URL = os.Getenv("SERVICE_REPOSITORY_URL")
|
||||||
|
|
||||||
sHAS_IS_DELETED := os.Getenv("HAS_IS_DELETED")
|
sHAS_IS_DELETED := os.Getenv("HAS_IS_DELETED")
|
||||||
|
|
||||||
sNEED_CRUD := os.Getenv("NEED_CRUD")
|
sNEED_CRUD := os.Getenv("NEED_CRUD")
|
||||||
@ -60,6 +66,9 @@ func FillSettings() {
|
|||||||
sNEED_NRPC := os.Getenv("NEED_NRPC")
|
sNEED_NRPC := os.Getenv("NEED_NRPC")
|
||||||
Settings.NEED_NRPC = BoolFromString(sNEED_NRPC)
|
Settings.NEED_NRPC = BoolFromString(sNEED_NRPC)
|
||||||
|
|
||||||
|
sNEED_MODEL_ONE_FOLDER := os.Getenv("NEED_MODEL_ONE_FOLDER")
|
||||||
|
Settings.NEED_MODEL_ONE_FOLDER = BoolFromString(sNEED_MODEL_ONE_FOLDER)
|
||||||
|
|
||||||
Settings.SERVICE_NAME = os.Getenv("SERVICE_NAME")
|
Settings.SERVICE_NAME = os.Getenv("SERVICE_NAME")
|
||||||
|
|
||||||
if Settings.TEMPLATE_FOLDERNAME == "" {
|
if Settings.TEMPLATE_FOLDERNAME == "" {
|
||||||
|
243
internal/create_files/crud_starter/crud_starter.go
Normal file
243
internal/create_files/crud_starter/crud_starter.go
Normal file
@ -0,0 +1,243 @@
|
|||||||
|
package crud_starter
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/ManyakRus/crud_generator/internal/config"
|
||||||
|
"github.com/ManyakRus/crud_generator/internal/constants"
|
||||||
|
"github.com/ManyakRus/crud_generator/internal/types"
|
||||||
|
"github.com/ManyakRus/starter/log"
|
||||||
|
"github.com/ManyakRus/starter/micro"
|
||||||
|
"os"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CreateAllFiles - создаёт все файлы в папке grpc
|
||||||
|
func CreateAllFiles(MapAll map[string]*types.Table) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
err = CreateFileCrudStarter(MapAll)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("CreateFileCrudStarter() error: ", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateFileCrudStarter - создаёт 1 файл в папке grpc
|
||||||
|
func CreateFileCrudStarter(MapAll map[string]*types.Table) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if config.Settings.NEED_CRUD == false {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
//чтение файлов
|
||||||
|
DirBin := micro.ProgramDir_bin()
|
||||||
|
//DirTemplates := DirBin + constants.FolderTemplates + micro.SeparatorFile()
|
||||||
|
DirReady := DirBin + constants.FolderReady + micro.SeparatorFile()
|
||||||
|
//DirTemplatesCrudStarter := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_CRUD_STARTER + micro.SeparatorFile()
|
||||||
|
//FilenameTemplateCrudStarter := DirTemplatesCrudStarter + "crud_starter.go_"
|
||||||
|
DirReadyCrudStarter := DirReady + "pkg" + micro.SeparatorFile() + "crud_starter" + micro.SeparatorFile()
|
||||||
|
FilenameReadyCrudStarter := DirReadyCrudStarter + "crud_starter.go"
|
||||||
|
|
||||||
|
//bytes, err := os.ReadFile(FilenameTemplateCrudStarter)
|
||||||
|
//if err != nil {
|
||||||
|
// log.Panic("ReadFile() ", FilenameTemplateCrudStarter, " error: ", err)
|
||||||
|
//}
|
||||||
|
//TextCrudStarter := string(bytes)
|
||||||
|
//
|
||||||
|
////заменим название сервиса
|
||||||
|
//TextCrudStarter = strings.ReplaceAll(TextCrudStarter, config.Settings.TEMPLATE_SERVICE_NAME, config.Settings.SERVICE_NAME)
|
||||||
|
|
||||||
|
TextCrudStarter := constants.TEXT_GENERATED + `package crud_starter`
|
||||||
|
|
||||||
|
//найдём новый текст для каждой таблицы
|
||||||
|
ModelURL := config.Settings.SERVICE_REPOSITORY_URL
|
||||||
|
if config.Settings.NEED_MODEL_ONE_FOLDER == false {
|
||||||
|
ModelURL = ModelURL + "/pkg/model"
|
||||||
|
}
|
||||||
|
|
||||||
|
//импорт
|
||||||
|
TextImport := FindTextImport(MapAll, ModelURL)
|
||||||
|
TextCrudStarter = TextCrudStarter + "\n" + TextImport
|
||||||
|
|
||||||
|
//DB
|
||||||
|
TextDB := FindTextDB(MapAll, ModelURL)
|
||||||
|
TextCrudStarter = TextCrudStarter + "\n" + TextDB
|
||||||
|
|
||||||
|
//GRPC
|
||||||
|
if config.Settings.NEED_GRPC == true {
|
||||||
|
TextGRPC := FindTextGRPC(MapAll, ModelURL)
|
||||||
|
TextCrudStarter = TextCrudStarter + "\n" + TextGRPC
|
||||||
|
}
|
||||||
|
|
||||||
|
//NRPC
|
||||||
|
if config.Settings.NEED_NRPC == true {
|
||||||
|
TextNRPC := FindTextNRPC(MapAll, ModelURL)
|
||||||
|
TextCrudStarter = TextCrudStarter + "\n" + TextNRPC
|
||||||
|
}
|
||||||
|
|
||||||
|
//запись файла
|
||||||
|
err = os.WriteFile(FilenameReadyCrudStarter, []byte(TextCrudStarter), constants.FILE_PERMISSIONS)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindTextImport - возвращает текст всех функций .proto для таблицы
|
||||||
|
func FindTextImport(MapAll map[string]*types.Table, ModelURL string) string {
|
||||||
|
Otvet := `
|
||||||
|
import (
|
||||||
|
model "` + ModelURL + `"`
|
||||||
|
//сортировка по названию таблиц
|
||||||
|
keys := make([]string, 0, len(MapAll))
|
||||||
|
for k := range MapAll {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
sort.Strings(keys)
|
||||||
|
|
||||||
|
TextDB := ""
|
||||||
|
TextGRPC := ""
|
||||||
|
TextNRPC := ""
|
||||||
|
for _, key1 := range keys {
|
||||||
|
Table1, ok := MapAll[key1]
|
||||||
|
if ok == false {
|
||||||
|
log.Panic("MapAll[key1] not found, key: ", key1)
|
||||||
|
}
|
||||||
|
TextDB = TextDB + FindTextImportDB1(Table1, ModelURL)
|
||||||
|
TextGRPC = TextGRPC + FindTextImportGRPC1(Table1, ModelURL)
|
||||||
|
TextNRPC = TextNRPC + FindTextImportNRPC1(Table1, ModelURL)
|
||||||
|
}
|
||||||
|
|
||||||
|
Otvet = Otvet + TextDB + "\n" + TextGRPC + "\n" + TextNRPC
|
||||||
|
|
||||||
|
Otvet = Otvet + "\n)"
|
||||||
|
|
||||||
|
return Otvet
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindTextImportDB1 - возвращает текст всех функций .proto для таблицы
|
||||||
|
func FindTextImportDB1(Table1 *types.Table, ModelURL string) string {
|
||||||
|
TableName := strings.ToLower(Table1.Name)
|
||||||
|
Otvet := "\n\t\"" + ModelURL + "/pkg/db/" + TableName + `"`
|
||||||
|
|
||||||
|
return Otvet
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindTextImportGRPC1 - возвращает текст всех функций .proto для таблицы
|
||||||
|
func FindTextImportGRPC1(Table1 *types.Table, ModelURL string) string {
|
||||||
|
TableName := strings.ToLower(Table1.Name)
|
||||||
|
Otvet := "\n\t\"" + ModelURL + "/pkg/grpc/grpc_client/grpc_" + TableName + `"`
|
||||||
|
|
||||||
|
return Otvet
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindTextImportNRPC1 - возвращает текст всех функций .proto для таблицы
|
||||||
|
func FindTextImportNRPC1(Table1 *types.Table, ModelURL string) string {
|
||||||
|
TableName := strings.ToLower(Table1.Name)
|
||||||
|
Otvet := "\n\t\"" + ModelURL + "/pkg/nrpc/grpc_client/nrpc_" + TableName + `"`
|
||||||
|
|
||||||
|
return Otvet
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindTextNRPC - возвращает текст всех функций .proto для таблицы
|
||||||
|
func FindTextDB(MapAll map[string]*types.Table, ModelURL string) string {
|
||||||
|
Otvet := `
|
||||||
|
// InitCrudTransport_DB - заполняет объекты crud для работы с БД напрямую
|
||||||
|
func InitCrudTransport_DB() {`
|
||||||
|
//сортировка по названию таблиц
|
||||||
|
keys := make([]string, 0, len(MapAll))
|
||||||
|
for k := range MapAll {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
sort.Strings(keys)
|
||||||
|
|
||||||
|
for _, key1 := range keys {
|
||||||
|
Table1, ok := MapAll[key1]
|
||||||
|
if ok == false {
|
||||||
|
log.Panic("MapAll[key1] not found, key: ", key1)
|
||||||
|
}
|
||||||
|
Otvet = Otvet + FindTextDB1(Table1)
|
||||||
|
}
|
||||||
|
|
||||||
|
Otvet = Otvet + "\n}"
|
||||||
|
|
||||||
|
return Otvet
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindTextNRPC1 - возвращает текст всех функций .proto для таблицы
|
||||||
|
func FindTextDB1(Table1 *types.Table) string {
|
||||||
|
TableName := strings.ToLower(Table1.Name)
|
||||||
|
ModelName := Table1.NameGo
|
||||||
|
Otvet := "\n\t" + "model." + ModelName + "{}.SetCrudInterface(db_" + TableName + ".Crud_DB{})"
|
||||||
|
|
||||||
|
return Otvet
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindTextNRPC - возвращает текст всех функций .proto для таблицы
|
||||||
|
func FindTextGRPC(MapAll map[string]*types.Table, ModelURL string) string {
|
||||||
|
Otvet := `
|
||||||
|
// InitCrudTransport_GRPC - заполняет объекты crud для работы с БД напрямую
|
||||||
|
func InitCrudTransport_GRPC() {`
|
||||||
|
//сортировка по названию таблиц
|
||||||
|
keys := make([]string, 0, len(MapAll))
|
||||||
|
for k := range MapAll {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
sort.Strings(keys)
|
||||||
|
|
||||||
|
for _, key1 := range keys {
|
||||||
|
Table1, ok := MapAll[key1]
|
||||||
|
if ok == false {
|
||||||
|
log.Panic("MapAll[key1] not found, key: ", key1)
|
||||||
|
}
|
||||||
|
Otvet = Otvet + FindTextGRPC1(Table1)
|
||||||
|
}
|
||||||
|
|
||||||
|
Otvet = Otvet + "\n}"
|
||||||
|
|
||||||
|
return Otvet
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindTextNRPC1 - возвращает текст всех функций .proto для таблицы
|
||||||
|
func FindTextGRPC1(Table1 *types.Table) string {
|
||||||
|
TableName := strings.ToLower(Table1.Name)
|
||||||
|
ModelName := Table1.NameGo
|
||||||
|
Otvet := "\n\t" + "model." + ModelName + "{}.SetCrudInterface(grpc_" + TableName + ".Crud_GRPC{})"
|
||||||
|
|
||||||
|
return Otvet
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindTextNRPC - возвращает текст всех функций .proto для таблицы
|
||||||
|
func FindTextNRPC(MapAll map[string]*types.Table, ModelURL string) string {
|
||||||
|
Otvet := `
|
||||||
|
// InitCrudTransport_NRPC - заполняет объекты crud для работы с БД напрямую
|
||||||
|
func InitCrudTransport_NRPC() {`
|
||||||
|
//сортировка по названию таблиц
|
||||||
|
keys := make([]string, 0, len(MapAll))
|
||||||
|
for k := range MapAll {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
sort.Strings(keys)
|
||||||
|
|
||||||
|
for _, key1 := range keys {
|
||||||
|
Table1, ok := MapAll[key1]
|
||||||
|
if ok == false {
|
||||||
|
log.Panic("MapAll[key1] not found, key: ", key1)
|
||||||
|
}
|
||||||
|
Otvet = Otvet + FindTextNRPC1(Table1)
|
||||||
|
}
|
||||||
|
|
||||||
|
Otvet = Otvet + "\n}"
|
||||||
|
|
||||||
|
return Otvet
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindTextNRPC1 - возвращает текст всех функций .proto для таблицы
|
||||||
|
func FindTextNRPC1(Table1 *types.Table) string {
|
||||||
|
TableName := strings.ToLower(Table1.Name)
|
||||||
|
ModelName := Table1.NameGo
|
||||||
|
Otvet := "\n\t" + "model." + ModelName + "{}.SetCrudInterface(nrpc_" + TableName + ".Crud_NRPC{})"
|
||||||
|
|
||||||
|
return Otvet
|
||||||
|
}
|
1
internal/create_files/crud_starter/crud_starter_test.go
Normal file
1
internal/create_files/crud_starter/crud_starter_test.go
Normal file
@ -0,0 +1 @@
|
|||||||
|
package crud_starter
|
@ -81,7 +81,8 @@ func CreateAllFolders() {
|
|||||||
}
|
}
|
||||||
log.Info("CreateFolder() ", Filename)
|
log.Info("CreateFolder() ", Filename)
|
||||||
}
|
}
|
||||||
//
|
|
||||||
|
//model
|
||||||
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "model"
|
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "model"
|
||||||
ok, err = micro.FileExists(Filename)
|
ok, err = micro.FileExists(Filename)
|
||||||
if ok == false || err != nil {
|
if ok == false || err != nil {
|
||||||
@ -91,7 +92,9 @@ func CreateAllFolders() {
|
|||||||
}
|
}
|
||||||
log.Info("CreateFolder() ", Filename)
|
log.Info("CreateFolder() ", Filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Settings.NEED_CRUD == true {
|
if config.Settings.NEED_CRUD == true {
|
||||||
|
//db
|
||||||
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "db"
|
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "db"
|
||||||
ok, err = micro.FileExists(Filename)
|
ok, err = micro.FileExists(Filename)
|
||||||
if ok == false || err != nil {
|
if ok == false || err != nil {
|
||||||
@ -101,6 +104,18 @@ func CreateAllFolders() {
|
|||||||
}
|
}
|
||||||
log.Info("CreateFolder() ", Filename)
|
log.Info("CreateFolder() ", Filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//crud_starter
|
||||||
|
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "crud_starter"
|
||||||
|
ok, err = micro.FileExists(Filename)
|
||||||
|
if ok == false || err != nil {
|
||||||
|
err = CreateFolder(Filename, 0777)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("CreateFolder() ", Filename, " error: ", err)
|
||||||
|
}
|
||||||
|
log.Info("CreateFolder() ", Filename)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Settings.NEED_GRPC == true {
|
if config.Settings.NEED_GRPC == true {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package logic
|
package logic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"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/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"
|
||||||
@ -63,6 +64,12 @@ func StartFillAll() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//crud_starter
|
||||||
|
err = crud_starter.CreateAllFiles(MapAll)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user