From c0fee0933a0fdb710b61c06c1b4235a060d71ff5 Mon Sep 17 00:00:00 2001 From: Nikitin Aleksandr Date: Wed, 25 Oct 2023 16:38:35 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20db?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/create_files/create_files.go | 8 ++++++- internal/create_files/db/db.go | 8 +++---- internal/folders/folders.go | 31 ++++++++++++++------------- internal/main.go | 3 +++ 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/internal/create_files/create_files.go b/internal/create_files/create_files.go index 9a553cb..f46410c 100644 --- a/internal/create_files/create_files.go +++ b/internal/create_files/create_files.go @@ -3,6 +3,7 @@ package create_files import ( "github.com/iancoleman/strcase" "github.com/jinzhu/inflection" + "strings" ) // FindSingularName - возвращает наименование в единственном числе @@ -22,7 +23,12 @@ func FindSingularName(s string) string { func FormatName(Name string) string { Otvet := Name - Otvet = strcase.ToCamel(Otvet) + switch strings.ToLower(Name) { + case "id": + Otvet = "ID" + default: + Otvet = strcase.ToCamel(Otvet) + } return Otvet } diff --git a/internal/create_files/db/db.go b/internal/create_files/db/db.go index 21c2dbb..4eaf7eb 100644 --- a/internal/create_files/db/db.go +++ b/internal/create_files/db/db.go @@ -47,10 +47,10 @@ func CreateDBFiles1(Table1 *types.Table) error { FilenameTemplateDB := DirTemplatesDB + "db.go_" TableName := strings.ToLower(Table1.Name) - FilenameReadyDB := DirReadyDB + TableName + micro.SeparatorFile() + TableName + ".go" + DirTable := DirReadyDB + "db_" + TableName + FilenameReadyDB := DirTable + micro.SeparatorFile() + "db_" + TableName + ".go" //создадим каталог - DirTable := DirReadyDB + TableName ok, err := micro.FileExists(DirTable) if ok == false { err = os.Mkdir(DirTable, 0777) @@ -98,10 +98,10 @@ func CreateDBTestFiles1(Table1 *types.Table) error { FilenameTemplateDB := DirTemplatesDB + "db_test.go_" TableName := strings.ToLower(Table1.Name) - FilenameReadyDB := DirReadyDB + TableName + micro.SeparatorFile() + TableName + "_test.go" + DirTable := DirReadyDB + "db_" + TableName + FilenameReadyDB := DirTable + micro.SeparatorFile() + "db_" + TableName + "_test.go" //создадим каталог - DirTable := DirReadyDB + TableName ok, err := micro.FileExists(DirTable) if ok == false { err = os.Mkdir(DirTable, 0777) diff --git a/internal/folders/folders.go b/internal/folders/folders.go index c9cbdb6..4fa3445 100644 --- a/internal/folders/folders.go +++ b/internal/folders/folders.go @@ -14,7 +14,7 @@ func CreateFolder(FilenameFull string, FilePermissions uint32) error { FileMode1 := os.FileMode(FilePermissions) if FilePermissions == 0 { - FileMode1 = os.FileMode(0700) + FileMode1 = os.FileMode(0777) } if _, err := os.Stat(FilenameFull); errors.Is(err, os.ErrNotExist) { @@ -43,21 +43,22 @@ func DeleteFolder(FilenameFull string) error { return err } +// CreateAllFolders - создаёт все нужные каталоги Ready func CreateAllFolders() { var err error - dir := micro.ProgramDir() + dir := micro.ProgramDir_bin() // Filename := dir + config.Settings.SERVICE_NAME - err = CreateFolder(Filename, 0) + err = CreateFolder(Filename, 0777) if err != nil { log.Panic("CreateFolder() ", Filename, " error: ", err) } // Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "internal" - err = CreateFolder(Filename, 0) + err = CreateFolder(Filename, 0777) if err != nil { log.Panic("CreateFolder() ", Filename, " error: ", err) } @@ -65,7 +66,7 @@ func CreateAllFolders() { // Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" - err = CreateFolder(Filename, 0) + err = CreateFolder(Filename, 0777) if err != nil { log.Panic("CreateFolder() ", Filename, " error: ", err) } @@ -73,7 +74,7 @@ func CreateAllFolders() { // Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "model" - err = CreateFolder(Filename, 0) + err = CreateFolder(Filename, 0777) if err != nil { log.Panic("CreateFolder() ", Filename, " error: ", err) } @@ -81,7 +82,7 @@ func CreateAllFolders() { if config.Settings.NEED_CRUD == true { Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "db" - err = CreateFolder(Filename, 0) + err = CreateFolder(Filename, 0777) if err != nil { log.Panic("CreateFolder() ", Filename, " error: ", err) } @@ -91,7 +92,7 @@ func CreateAllFolders() { if config.Settings.NEED_GRPC == true { // Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "grpc" - err = CreateFolder(Filename, 0) + err = CreateFolder(Filename, 0777) if err != nil { log.Panic("CreateFolder() ", Filename, " error: ", err) } @@ -99,7 +100,7 @@ func CreateAllFolders() { // Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "grpc" + micro.SeparatorFile() + "grpc_server" - err = CreateFolder(Filename, 0) + err = CreateFolder(Filename, 0777) if err != nil { log.Panic("CreateFolder() ", Filename, " error: ", err) } @@ -107,7 +108,7 @@ func CreateAllFolders() { // Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "grpc" + micro.SeparatorFile() + "grpc_client" - err = CreateFolder(Filename, 0) + err = CreateFolder(Filename, 0777) if err != nil { log.Panic("CreateFolder() ", Filename, " error: ", err) } @@ -115,7 +116,7 @@ func CreateAllFolders() { // Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "grpc" + micro.SeparatorFile() + "grpc_proto" - err = CreateFolder(Filename, 0) + err = CreateFolder(Filename, 0777) if err != nil { log.Panic("CreateFolder() ", Filename, " error: ", err) } @@ -125,7 +126,7 @@ func CreateAllFolders() { if config.Settings.NEED_NRPC == true { // Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "nrpc" - err = CreateFolder(Filename, 0) + err = CreateFolder(Filename, 0777) if err != nil { log.Panic("CreateFolder() ", Filename, " error: ", err) } @@ -133,7 +134,7 @@ func CreateAllFolders() { // Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "grpc" + micro.SeparatorFile() + "nrpc_server" - err = CreateFolder(Filename, 0) + err = CreateFolder(Filename, 0777) if err != nil { log.Panic("CreateFolder() ", Filename, " error: ", err) } @@ -141,7 +142,7 @@ func CreateAllFolders() { // Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "grpc" + micro.SeparatorFile() + "nrpc_client" - err = CreateFolder(Filename, 0) + err = CreateFolder(Filename, 0777) if err != nil { log.Panic("CreateFolder() ", Filename, " error: ", err) } @@ -149,7 +150,7 @@ func CreateAllFolders() { // Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "grpc" + micro.SeparatorFile() + "grpc_proto" - err = CreateFolder(Filename, 0) + err = CreateFolder(Filename, 0777) if err != nil { log.Panic("CreateFolder() ", Filename, " error: ", err) } diff --git a/internal/main.go b/internal/main.go index f148afa..2fcb0e2 100644 --- a/internal/main.go +++ b/internal/main.go @@ -3,6 +3,7 @@ package main 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/crud_generator/internal/load_configs" "github.com/ManyakRus/crud_generator/internal/logic" ConfigMain "github.com/ManyakRus/starter/config" @@ -24,6 +25,8 @@ func StartApp() { postgres_gorm.StartDB() postgres_gorm.GetConnection().Logger.LogMode(1) + folders.CreateAllFolders() + log.Info("postgres host: ", postgres_gorm.Settings.DB_HOST) err := logic.StartFillAll() if err != nil {