1
0
mirror of https://github.com/ManyakRus/crud_generator.git synced 2024-12-20 12:30:52 +02:00
crud_generator/internal/folders/folders.go

215 lines
6.2 KiB
Go
Raw Normal View History

2023-10-06 15:48:58 +02:00
package folders
import (
"errors"
"github.com/ManyakRus/crud_generator/internal/config"
"github.com/ManyakRus/starter/log"
"github.com/ManyakRus/starter/micro"
"os"
)
// CreateFolder - создаёт папку на диске
func CreateFolder(FilenameFull string, FilePermissions uint32) error {
var err error
FileMode1 := os.FileMode(FilePermissions)
if FilePermissions == 0 {
2023-10-25 15:38:35 +02:00
FileMode1 = os.FileMode(0777)
2023-10-06 15:48:58 +02:00
}
if _, err := os.Stat(FilenameFull); errors.Is(err, os.ErrNotExist) {
2023-11-01 16:34:57 +02:00
err := os.MkdirAll(FilenameFull, FileMode1)
2023-10-06 15:48:58 +02:00
if err != nil {
return err
}
}
return err
}
// DeleteFolder - создаёт папку на диске
func DeleteFolder(FilenameFull string) error {
var err error
if _, err := os.Stat(FilenameFull); errors.Is(err, os.ErrNotExist) {
return err
}
err = os.RemoveAll(FilenameFull)
if err != nil {
return err
}
return err
}
2023-10-25 15:38:35 +02:00
// CreateAllFolders - создаёт все нужные каталоги Ready
2023-10-06 15:48:58 +02:00
func CreateAllFolders() {
var err error
2023-10-25 15:38:35 +02:00
dir := micro.ProgramDir_bin()
2023-10-06 15:48:58 +02:00
//
Filename := dir + config.Settings.SERVICE_NAME
2023-10-25 16:30:18 +02:00
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)
2023-10-06 15:48:58 +02:00
}
//
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "internal"
2023-10-25 16:30:18 +02:00
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)
2023-10-06 15:48:58 +02:00
}
//
2023-11-01 16:34:57 +02:00
//Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg"
//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)
//}
2023-10-26 16:03:50 +02:00
//model
2023-11-01 16:34:57 +02:00
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_MODEL
2023-10-25 16:30:18 +02:00
ok, err = micro.FileExists(Filename)
if ok == false || err != nil {
2023-10-25 15:38:35 +02:00
err = CreateFolder(Filename, 0777)
2023-10-06 15:48:58 +02:00
if err != nil {
log.Panic("CreateFolder() ", Filename, " error: ", err)
}
log.Info("CreateFolder() ", Filename)
}
2023-10-26 16:03:50 +02:00
2023-10-25 16:30:18 +02:00
if config.Settings.NEED_CRUD == true {
2023-10-26 16:03:50 +02:00
//db
2023-11-01 16:34:57 +02:00
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_DB
2023-10-25 16:30:18 +02:00
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)
}
2023-10-26 16:03:50 +02:00
//crud_starter
2023-11-01 16:34:57 +02:00
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_CRUD_STARTER
2023-10-26 16:03:50 +02:00
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)
}
2023-10-25 16:30:18 +02:00
}
2023-10-06 15:48:58 +02:00
if config.Settings.NEED_GRPC == true {
2023-11-07 16:58:02 +02:00
//grpc
2023-11-01 16:34:57 +02:00
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_GRPC
2023-10-25 16:30:18 +02:00
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)
2023-10-06 15:48:58 +02:00
}
2023-11-07 16:58:02 +02:00
//grpc_server
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_GRPC_SERVER
2023-10-25 16:30:18 +02:00
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)
2023-10-06 15:48:58 +02:00
}
2023-11-07 16:58:02 +02:00
//grpc client
2023-11-01 16:34:57 +02:00
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_GRPC + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT
2023-10-25 16:30:18 +02:00
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)
2023-10-06 15:48:58 +02:00
}
2023-11-07 16:58:02 +02:00
//grpc_proto
2023-11-01 16:34:57 +02:00
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_GRPC + micro.SeparatorFile() + "grpc_proto"
2023-10-25 16:30:18 +02:00
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)
2023-10-06 15:48:58 +02:00
}
}
if config.Settings.NEED_NRPC == true {
2023-11-07 16:58:02 +02:00
//nrpc
2023-11-01 16:34:57 +02:00
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_NRPC
2023-10-25 16:30:18 +02:00
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)
2023-10-06 15:48:58 +02:00
}
2023-11-07 16:58:02 +02:00
//server_nrpc
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_NRPC_SERVER
2023-10-25 16:30:18 +02:00
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)
2023-10-06 15:48:58 +02:00
}
2023-11-07 16:58:02 +02:00
//nrpc client
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_NRPC_CLIENT
2023-10-25 16:30:18 +02:00
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)
2023-10-06 15:48:58 +02:00
}
2023-11-07 16:58:02 +02:00
//grpc_proto
2023-11-01 16:34:57 +02:00
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + config.Settings.TEMPLATE_FOLDERNAME_GRPC + micro.SeparatorFile() + "grpc_proto"
2023-10-25 16:30:18 +02:00
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)
2023-10-06 15:48:58 +02:00
}
}
//return err
}