1
0
mirror of https://github.com/ManyakRus/crud_generator.git synced 2025-01-03 01:22:21 +02:00

сделал db

This commit is contained in:
Nikitin Aleksandr 2023-10-25 16:38:35 +03:00
parent 9f2716f678
commit c0fee0933a
4 changed files with 30 additions and 20 deletions

View File

@ -3,6 +3,7 @@ package create_files
import ( import (
"github.com/iancoleman/strcase" "github.com/iancoleman/strcase"
"github.com/jinzhu/inflection" "github.com/jinzhu/inflection"
"strings"
) )
// FindSingularName - возвращает наименование в единственном числе // FindSingularName - возвращает наименование в единственном числе
@ -22,7 +23,12 @@ func FindSingularName(s string) string {
func FormatName(Name string) string { func FormatName(Name string) string {
Otvet := Name Otvet := Name
Otvet = strcase.ToCamel(Otvet) switch strings.ToLower(Name) {
case "id":
Otvet = "ID"
default:
Otvet = strcase.ToCamel(Otvet)
}
return Otvet return Otvet
} }

View File

@ -47,10 +47,10 @@ func CreateDBFiles1(Table1 *types.Table) error {
FilenameTemplateDB := DirTemplatesDB + "db.go_" FilenameTemplateDB := DirTemplatesDB + "db.go_"
TableName := strings.ToLower(Table1.Name) 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) ok, err := micro.FileExists(DirTable)
if ok == false { if ok == false {
err = os.Mkdir(DirTable, 0777) err = os.Mkdir(DirTable, 0777)
@ -98,10 +98,10 @@ func CreateDBTestFiles1(Table1 *types.Table) error {
FilenameTemplateDB := DirTemplatesDB + "db_test.go_" FilenameTemplateDB := DirTemplatesDB + "db_test.go_"
TableName := strings.ToLower(Table1.Name) 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) ok, err := micro.FileExists(DirTable)
if ok == false { if ok == false {
err = os.Mkdir(DirTable, 0777) err = os.Mkdir(DirTable, 0777)

View File

@ -14,7 +14,7 @@ func CreateFolder(FilenameFull string, FilePermissions uint32) error {
FileMode1 := os.FileMode(FilePermissions) FileMode1 := os.FileMode(FilePermissions)
if FilePermissions == 0 { if FilePermissions == 0 {
FileMode1 = os.FileMode(0700) FileMode1 = os.FileMode(0777)
} }
if _, err := os.Stat(FilenameFull); errors.Is(err, os.ErrNotExist) { if _, err := os.Stat(FilenameFull); errors.Is(err, os.ErrNotExist) {
@ -43,21 +43,22 @@ func DeleteFolder(FilenameFull string) error {
return err return err
} }
// CreateAllFolders - создаёт все нужные каталоги Ready
func CreateAllFolders() { func CreateAllFolders() {
var err error var err error
dir := micro.ProgramDir() dir := micro.ProgramDir_bin()
// //
Filename := dir + config.Settings.SERVICE_NAME Filename := dir + config.Settings.SERVICE_NAME
err = CreateFolder(Filename, 0) err = CreateFolder(Filename, 0777)
if err != nil { if err != nil {
log.Panic("CreateFolder() ", Filename, " error: ", err) log.Panic("CreateFolder() ", Filename, " error: ", err)
} }
// //
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "internal" Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "internal"
err = CreateFolder(Filename, 0) err = CreateFolder(Filename, 0777)
if err != nil { if err != nil {
log.Panic("CreateFolder() ", Filename, " error: ", err) log.Panic("CreateFolder() ", Filename, " error: ", err)
} }
@ -65,7 +66,7 @@ func CreateAllFolders() {
// //
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg"
err = CreateFolder(Filename, 0) err = CreateFolder(Filename, 0777)
if err != nil { if err != nil {
log.Panic("CreateFolder() ", Filename, " error: ", err) log.Panic("CreateFolder() ", Filename, " error: ", err)
} }
@ -73,7 +74,7 @@ func CreateAllFolders() {
// //
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "model" Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "model"
err = CreateFolder(Filename, 0) err = CreateFolder(Filename, 0777)
if err != nil { if err != nil {
log.Panic("CreateFolder() ", Filename, " error: ", err) log.Panic("CreateFolder() ", Filename, " error: ", err)
} }
@ -81,7 +82,7 @@ func CreateAllFolders() {
if config.Settings.NEED_CRUD == true { if config.Settings.NEED_CRUD == true {
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "db" Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "db"
err = CreateFolder(Filename, 0) err = CreateFolder(Filename, 0777)
if err != nil { if err != nil {
log.Panic("CreateFolder() ", Filename, " error: ", err) log.Panic("CreateFolder() ", Filename, " error: ", err)
} }
@ -91,7 +92,7 @@ func CreateAllFolders() {
if config.Settings.NEED_GRPC == true { if config.Settings.NEED_GRPC == true {
// //
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "grpc" Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "grpc"
err = CreateFolder(Filename, 0) err = CreateFolder(Filename, 0777)
if err != nil { if err != nil {
log.Panic("CreateFolder() ", Filename, " error: ", err) 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" 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 { if err != nil {
log.Panic("CreateFolder() ", Filename, " error: ", err) 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" 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 { if err != nil {
log.Panic("CreateFolder() ", Filename, " error: ", err) 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" 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 { if err != nil {
log.Panic("CreateFolder() ", Filename, " error: ", err) log.Panic("CreateFolder() ", Filename, " error: ", err)
} }
@ -125,7 +126,7 @@ func CreateAllFolders() {
if config.Settings.NEED_NRPC == true { if config.Settings.NEED_NRPC == true {
// //
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "nrpc" Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "nrpc"
err = CreateFolder(Filename, 0) err = CreateFolder(Filename, 0777)
if err != nil { if err != nil {
log.Panic("CreateFolder() ", Filename, " error: ", err) 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" 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 { if err != nil {
log.Panic("CreateFolder() ", Filename, " error: ", err) 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" 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 { if err != nil {
log.Panic("CreateFolder() ", Filename, " error: ", err) 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" 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 { if err != nil {
log.Panic("CreateFolder() ", Filename, " error: ", err) log.Panic("CreateFolder() ", Filename, " error: ", err)
} }

View File

@ -3,6 +3,7 @@ package main
import ( import (
"github.com/ManyakRus/crud_generator/internal/config" "github.com/ManyakRus/crud_generator/internal/config"
"github.com/ManyakRus/crud_generator/internal/constants" "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/load_configs"
"github.com/ManyakRus/crud_generator/internal/logic" "github.com/ManyakRus/crud_generator/internal/logic"
ConfigMain "github.com/ManyakRus/starter/config" ConfigMain "github.com/ManyakRus/starter/config"
@ -24,6 +25,8 @@ func StartApp() {
postgres_gorm.StartDB() postgres_gorm.StartDB()
postgres_gorm.GetConnection().Logger.LogMode(1) postgres_gorm.GetConnection().Logger.LogMode(1)
folders.CreateAllFolders()
log.Info("postgres host: ", postgres_gorm.Settings.DB_HOST) log.Info("postgres host: ", postgres_gorm.Settings.DB_HOST)
err := logic.StartFillAll() err := logic.StartFillAll()
if err != nil { if err != nil {