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) {
|
|
|
|
err := os.Mkdir(FilenameFull, FileMode1)
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg"
|
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-10-26 16:03:50 +02:00
|
|
|
|
|
|
|
//model
|
2023-10-06 15:48:58 +02:00
|
|
|
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "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-10-25 16:30:18 +02:00
|
|
|
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "db"
|
|
|
|
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
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2023-10-25 16:30:18 +02:00
|
|
|
}
|
2023-10-06 15:48:58 +02:00
|
|
|
|
|
|
|
if config.Settings.NEED_GRPC == true {
|
|
|
|
//
|
|
|
|
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "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-10-26 10:33:12 +02:00
|
|
|
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "internal" + micro.SeparatorFile() + "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
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "grpc" + micro.SeparatorFile() + "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
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "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 {
|
|
|
|
//
|
|
|
|
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "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-10-26 10:33:12 +02:00
|
|
|
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "internal" + micro.SeparatorFile() + "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-10-26 10:33:12 +02:00
|
|
|
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "nrpc" + micro.SeparatorFile() + "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
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
Filename = dir + config.Settings.SERVICE_NAME + micro.SeparatorFile() + "pkg" + micro.SeparatorFile() + "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
|
|
|
|
}
|