1
0
mirror of https://github.com/ManyakRus/crud_generator.git synced 2025-01-17 08:56:48 +02:00

сделал ReplacePackageName()

This commit is contained in:
Nikitin Aleksandr 2023-11-17 13:23:15 +03:00
parent e86f662601
commit 4ab4024d8b
13 changed files with 92 additions and 35 deletions

4
go.mod
View File

@ -3,7 +3,7 @@ module github.com/ManyakRus/crud_generator
go 1.20
require (
github.com/ManyakRus/starter v0.0.0-20231115082945-e2f3f8f5ed62
github.com/ManyakRus/starter v0.0.0-20231117100514-f4caf3891bce
github.com/bxcodec/faker/v3 v3.8.1
github.com/davecgh/go-spew v1.1.1
github.com/iancoleman/strcase v0.3.0
@ -13,7 +13,7 @@ require (
github.com/ompluscator/dynamic-struct v1.4.0
github.com/otiai10/copy v1.14.0
github.com/serenize/snaker v0.0.0-20201027110005-a7ad2135616e
gitlab.aescorp.ru/dsp_dev/claim/sync_service v1.2.24
gitlab.aescorp.ru/dsp_dev/claim/sync_service v1.2.26
golang.org/x/tools v0.15.0
gorm.io/gorm v1.25.5
)

8
go.sum
View File

@ -3,8 +3,8 @@ github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.11.0/go.mod h1:HcM1YX14R7CJc
github.com/Azure/azure-sdk-for-go/sdk/internal v0.7.0/go.mod h1:yqy467j36fJxcRV2TzfVZ1pCb5vxm4BtZPUdYWe/Xo8=
github.com/ManyakRus/logrus v0.0.0-20231019115155-9e6fede0d792 h1:bxwxD0H3kSUAH3uNk/b74gkImcUiP7dyibmMoVwk338=
github.com/ManyakRus/logrus v0.0.0-20231019115155-9e6fede0d792/go.mod h1:OUyxCVbPW/2lC1e6cM7Am941SJiC88BhNnb24x2R3a8=
github.com/ManyakRus/starter v0.0.0-20231115082945-e2f3f8f5ed62 h1:ajjWHc+dktmSXEbfVdZqWThYBfhGqIdPTWQUTy/H5p0=
github.com/ManyakRus/starter v0.0.0-20231115082945-e2f3f8f5ed62/go.mod h1:a+wYuguDadLR6xaj9fN8m6acWhUjzPuxaPtZfJhMNW4=
github.com/ManyakRus/starter v0.0.0-20231117100514-f4caf3891bce h1:13ozzODjO4WargasPbewy4a+L8DJ+shs+cuCuOq4GYU=
github.com/ManyakRus/starter v0.0.0-20231117100514-f4caf3891bce/go.mod h1:a+wYuguDadLR6xaj9fN8m6acWhUjzPuxaPtZfJhMNW4=
github.com/bxcodec/faker/v3 v3.8.1 h1:qO/Xq19V6uHt2xujwpaetgKhraGCapqY2CRWGD/SqcM=
github.com/bxcodec/faker/v3 v3.8.1/go.mod h1:DdSDccxF5msjFo5aO4vrobRQ8nIApg8kq3QWPEQD6+o=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
@ -127,8 +127,8 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
gitlab.aescorp.ru/dsp_dev/claim/sync_service v1.2.24 h1:sUIyfhb7Yq3hVeqFu0ti1zVhk5NDuGgoIbYXFecBhFU=
gitlab.aescorp.ru/dsp_dev/claim/sync_service v1.2.24/go.mod h1:WDjha5KBoluGomO6iq41ZDiEaEFj1KPHtOSf9+usk/s=
gitlab.aescorp.ru/dsp_dev/claim/sync_service v1.2.26 h1:jcII3+d63i6JCiv9uKDcD413No+Fmd50jNbQ19F1YYc=
gitlab.aescorp.ru/dsp_dev/claim/sync_service v1.2.26/go.mod h1:79bzXRg7wjmLFHkXiCmM/9VZTxwKudzaXR+TfsGxWVs=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=

View File

@ -568,8 +568,12 @@ func FindModelNameComment(ModelName string, Table1 *types.Table) string {
func ReplacePackageName(Text, PackageName string) string {
Otvet := Text
//найдём имя каталога, это будет имя пакета
PackageName = micro.DeleteEndSlash(PackageName)
PackageName = micro.LastWord(PackageName)
//
TextFind := "\tpackage "
TextFind := "package "
pos1 := strings.Index(Otvet, TextFind)
if pos1 < 0 {
log.Error("not found word: package ")

View File

@ -76,6 +76,9 @@ func CreateFiles(Table1 *types.Table) error {
}
TextDB := string(bytes)
//заменим имя пакета на новое
create_files.ReplacePackageName(TextDB, DirTable)
//создание текста
ModelName := Table1.NameGo
TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
@ -136,6 +139,9 @@ func CreateTestFiles(Table1 *types.Table) error {
}
TextDB := string(bytes)
//заменим имя пакета на новое
create_files.ReplacePackageName(TextDB, DirTable)
//создание текста
ModelName := Table1.NameGo
TextDB = strings.ReplaceAll(TextDB, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)

View File

@ -78,6 +78,9 @@ func CreateFilesTable_struct(Table1 *types.Table, DirTemplatesTable, DirReadyTab
}
TextModel := string(bytes)
//заменим имя пакета на новое
create_files.ReplacePackageName(TextModel, DirReadyTable)
//создание текста
TextModel, TextModelStruct, ModelName, err := FindTextModelStruct(TextModel, Table1)
TextModel = ReplaceModelStruct(TextModel, TextModelStruct)

View File

@ -56,15 +56,15 @@ func CreateFiles(Table1 *types.Table) error {
FilenameTemplateGRPCClient := DirTemplatesGRPCClient + "grpc_client.go_"
TableName := strings.ToLower(Table1.Name)
DirTable := DirReadyGRPCClient + "grpc_" + TableName + micro.SeparatorFile()
FilenameReadyGRPCClient := DirTable + "grpc_" + TableName + ".go"
DirReadyTable := DirReadyGRPCClient + "grpc_" + TableName + micro.SeparatorFile()
FilenameReadyGRPCClient := DirReadyTable + "grpc_" + TableName + ".go"
//создадим каталог
ok, err := micro.FileExists(DirTable)
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirTable, 0777)
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirTable, " error: ", err)
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
@ -74,6 +74,9 @@ func CreateFiles(Table1 *types.Table) error {
}
TextGRPCClient := string(bytes)
//заменим имя пакета на новое
create_files.ReplacePackageName(TextGRPCClient, DirReadyTable)
//создание текста
ModelName := Table1.NameGo
TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
@ -131,15 +134,15 @@ func CreateTestFiles(Table1 *types.Table) error {
FilenameTemplateGRPCClient := DirTemplatesGRPCClient + "grpc_client_test.go_"
TableName := strings.ToLower(Table1.Name)
DirTable := DirReadyGRPCClient + "grpc_" + TableName + micro.SeparatorFile()
FilenameReadyGRPCClient := DirTable + "grpc_" + TableName + "_test.go"
DirReadyTable := DirReadyGRPCClient + "grpc_" + TableName + micro.SeparatorFile()
FilenameReadyGRPCClient := DirReadyTable + "grpc_" + TableName + "_test.go"
//создадим каталог
ok, err := micro.FileExists(DirTable)
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.Mkdir(DirTable, 0777)
err = os.Mkdir(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirTable, " error: ", err)
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
@ -149,6 +152,9 @@ func CreateTestFiles(Table1 *types.Table) error {
}
TextGRPCClient := string(bytes)
//заменим имя пакета на новое
create_files.ReplacePackageName(TextGRPCClient, DirReadyTable)
//создание текста
ModelName := Table1.NameGo
TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)

View File

@ -55,8 +55,8 @@ func CreateFiles(Table1 *types.Table) error {
FilenameTemplateGRPCServer := DirTemplatesGRPCServer + "server_grpc.go_"
TableName := strings.ToLower(Table1.Name)
DirTable := DirReadyGRPCServer
FilenameReadyGRPCServer := DirTable + config.Settings.PREFIX_SERVER_GRPC + TableName + ".go"
DirReadyTable := DirReadyGRPCServer
FilenameReadyGRPCServer := DirReadyTable + config.Settings.PREFIX_SERVER_GRPC + TableName + ".go"
bytes, err := os.ReadFile(FilenameTemplateGRPCServer)
if err != nil {
@ -64,6 +64,9 @@ func CreateFiles(Table1 *types.Table) error {
}
TextGRPCServer := string(bytes)
//заменим имя пакета на новое
create_files.ReplacePackageName(TextGRPCServer, DirReadyTable)
//создание текста
ModelName := Table1.NameGo
TextGRPCServer = strings.ReplaceAll(TextGRPCServer, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
@ -112,8 +115,8 @@ func CreateTestFiles(Table1 *types.Table) error {
FilenameTemplateGRPCServer := DirTemplatesGRPCServer + "server_grpc_test.go_"
TableName := strings.ToLower(Table1.Name)
DirTable := DirReadyGRPCServer
FilenameReadyGRPCServer := DirTable + config.Settings.PREFIX_SERVER_GRPC + TableName + "_test.go"
DirReadyTable := DirReadyGRPCServer
FilenameReadyGRPCServer := DirReadyTable + config.Settings.PREFIX_SERVER_GRPC + TableName + "_test.go"
bytes, err := os.ReadFile(FilenameTemplateGRPCServer)
if err != nil {
@ -121,6 +124,9 @@ func CreateTestFiles(Table1 *types.Table) error {
}
TextGRPCServer := string(bytes)
//заменим имя пакета на новое
create_files.ReplacePackageName(TextGRPCServer, DirReadyTable)
//создание текста
ModelName := Table1.NameGo
TextGRPCServer = strings.ReplaceAll(TextGRPCServer, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)

View File

@ -87,6 +87,9 @@ func CreateFilesModel_struct(Table1 *types.Table, DirTemplatesModel, DirReadyMod
}
TextModel := string(bytes)
//заменим имя пакета на новое
create_files.ReplacePackageName(TextModel, DirReadyModel)
//создание текста
//TextModel, TextModelStruct, ModelName, err := FindTextModelStruct(TextModel, Table1)
//TextModel = ReplaceModelStruct(TextModel, TextModelStruct)
@ -145,9 +148,10 @@ func CreateFilesModel_crud(Table1 *types.Table, DirTemplatesModel, DirReadyModel
}
TextModel := string(bytes)
//создание текста
//заменим имя пакета на новое
create_files.ReplacePackageName(TextModel, DirReadyModel)
//
//создание текста
TextModel = strings.ReplaceAll(TextModel, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
TextModel = strings.ReplaceAll(TextModel, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
TextModel = config.Settings.TEXT_MODULE_GENERATED + TextModel

View File

@ -55,15 +55,15 @@ func CreateFiles(Table1 *types.Table) error {
FilenameTemplateNRPCClient := DirTemplatesNRPCClient + "nrpc_client.go_"
TableName := strings.ToLower(Table1.Name)
DirTable := DirReadyNRPCClient + "nrpc_" + TableName + micro.SeparatorFile()
FilenameReadyNRPCClient := DirTable + "nrpc_" + TableName + ".go"
DirReadyTable := DirReadyNRPCClient + "nrpc_" + TableName + micro.SeparatorFile()
FilenameReadyNRPCClient := DirReadyTable + "nrpc_" + TableName + ".go"
//создадим каталог
ok, err := micro.FileExists(DirTable)
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirTable, 0777)
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirTable, " error: ", err)
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
@ -73,6 +73,9 @@ func CreateFiles(Table1 *types.Table) error {
}
TextNRPCClient := string(bytes)
//заменим имя пакета на новое
create_files.ReplacePackageName(TextNRPCClient, DirReadyTable)
//создание текста
ModelName := Table1.NameGo
TextNRPCClient = strings.ReplaceAll(TextNRPCClient, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
@ -109,15 +112,15 @@ func CreateTestFiles(Table1 *types.Table) error {
FilenameTemplateNRPCClient := DirTemplatesNRPCClient + "nrpc_client_test.go_"
TableName := strings.ToLower(Table1.Name)
DirTable := DirReadyNRPCClient + "nrpc_" + TableName + micro.SeparatorFile()
FilenameReadyNRPCClient := DirTable + "nrpc_" + TableName + "_test.go"
DirReadyTable := DirReadyNRPCClient + "nrpc_" + TableName + micro.SeparatorFile()
FilenameReadyNRPCClient := DirReadyTable + "nrpc_" + TableName + "_test.go"
//создадим каталог
ok, err := micro.FileExists(DirTable)
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirTable, 0777)
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirTable, " error: ", err)
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
@ -127,6 +130,9 @@ func CreateTestFiles(Table1 *types.Table) error {
}
TextNRPCClient := string(bytes)
//заменим имя пакета на новое
create_files.ReplacePackageName(TextNRPCClient, DirReadyTable)
//создание текста
ModelName := Table1.NameGo
TextNRPCClient = strings.ReplaceAll(TextNRPCClient, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)

View File

@ -47,6 +47,9 @@ func CreateServerGRPCStarter() error {
}
TextGRPCStarter := string(bytes)
//заменим имя пакета на новое
create_files.ReplacePackageName(TextGRPCStarter, DirReadyServerGRPC)
//создадим папку ready
folders.CreateFolder(DirReadyServerGRPC)

View File

@ -46,6 +46,9 @@ func CreateServerGRPCStarter() error {
}
TextNRPCStarter := string(bytes)
//заменим имя пакета на новое
create_files.ReplacePackageName(TextNRPCStarter, DirReadyServerNRPC)
//создадим папку ready
folders.CreateFolder(DirReadyServerNRPC)

View File

@ -776,3 +776,19 @@ func StringFromLowerCase(s string) string {
return Otvet
}
// DeleteEndSlash - убирает в конце / или \
func DeleteEndSlash(Text string) string {
Otvet := Text
if Otvet == "" {
return Otvet
}
LastSymbol := Otvet[len(Otvet)-1:]
if LastSymbol == "/" || LastSymbol == `\` {
Otvet = Otvet[0 : len(Otvet)-1]
}
return Otvet
}

4
vendor/modules.txt vendored
View File

@ -1,7 +1,7 @@
# github.com/ManyakRus/logrus v0.0.0-20231019115155-9e6fede0d792
## explicit; go 1.13
github.com/ManyakRus/logrus
# github.com/ManyakRus/starter v0.0.0-20231115082945-e2f3f8f5ed62
# github.com/ManyakRus/starter v0.0.0-20231117100514-f4caf3891bce
## explicit; go 1.20
github.com/ManyakRus/starter/config
github.com/ManyakRus/starter/contextmain
@ -70,7 +70,7 @@ github.com/otiai10/copy
# github.com/serenize/snaker v0.0.0-20201027110005-a7ad2135616e
## explicit
github.com/serenize/snaker
# gitlab.aescorp.ru/dsp_dev/claim/sync_service v1.2.24
# gitlab.aescorp.ru/dsp_dev/claim/sync_service v1.2.26
## explicit; go 1.20
gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_client/constants
# golang.org/x/crypto v0.15.0