1
0
mirror of https://github.com/ManyakRus/crud_generator.git synced 2024-12-16 21:52:42 +02:00
crud_generator/internal/config/config.go

123 lines
4.0 KiB
Go
Raw Normal View History

2023-09-28 16:45:44 +02:00
package config
import (
2023-10-23 17:09:55 +02:00
"log"
2023-09-28 16:45:44 +02:00
"os"
2023-10-06 15:48:58 +02:00
"strings"
2023-09-28 16:45:44 +02:00
)
// Settings хранит все нужные переменные окружения
var Settings SettingsINI
// SettingsINI - структура для хранения всех нужных переменных окружения
type SettingsINI struct {
2023-10-26 16:03:50 +02:00
INCLUDE_TABLES string
EXCLUDE_TABLES string
TEMPLATE_FOLDERNAME string
TEMPLATE_FOLDERNAME_MODEL string
TEMPLATE_FOLDERNAME_DB string
TEMPLATE_FOLDERNAME_GRPC string
TEMPLATE_FOLDERNAME_GRPC_SERVER string
TEMPLATE_FOLDERNAME_GRPC_CLIENT string
TEMPLATE_FOLDERNAME_NRPC string
TEMPLATE_FOLDERNAME_NRPC_SERVER string
TEMPLATE_FOLDERNAME_NRPC_CLIENT string
TEMPLATE_SERVICE_NAME string
TEMPLATE_FOLDERNAME_CRUD_STARTER string
NEED_CRUD bool
NEED_GRPC bool
NEED_NRPC bool
SERVICE_NAME string
SERVICE_REPOSITORY_URL string
TEXT_TEMPLATE_MODEL string
TEXT_TEMPLATE_TABLENAME string
HAS_IS_DELETED bool
2023-11-01 16:34:57 +02:00
READY_FOLDERNAME string
2023-09-28 16:45:44 +02:00
}
// FillSettings загружает переменные окружения в структуру из переменных окружения
func FillSettings() {
2023-11-01 16:34:57 +02:00
//dir := micro.ProgramDir_bin()
2023-09-28 16:45:44 +02:00
Settings = SettingsINI{}
Settings.INCLUDE_TABLES = os.Getenv("INCLUDE_TABLES")
Settings.EXCLUDE_TABLES = os.Getenv("EXCLUDE_TABLES")
2023-10-23 17:09:55 +02:00
Settings.TEMPLATE_FOLDERNAME = os.Getenv("TEMPLATE_FOLDERNAME")
Settings.TEMPLATE_FOLDERNAME_MODEL = os.Getenv("TEMPLATE_FOLDERNAME_MODEL")
Settings.TEMPLATE_FOLDERNAME_DB = os.Getenv("TEMPLATE_FOLDERNAME_DB")
Settings.TEMPLATE_FOLDERNAME_GRPC = os.Getenv("TEMPLATE_FOLDERNAME_GRPC")
2023-10-26 10:33:12 +02:00
Settings.TEMPLATE_FOLDERNAME_GRPC_SERVER = os.Getenv("TEMPLATE_FOLDERNAME_GRPC_SERVER")
Settings.TEMPLATE_FOLDERNAME_GRPC_CLIENT = os.Getenv("TEMPLATE_FOLDERNAME_GRPC_CLIENT")
2023-10-23 17:09:55 +02:00
Settings.TEMPLATE_FOLDERNAME_NRPC = os.Getenv("TEMPLATE_FOLDERNAME_NRPC")
2023-10-26 10:33:12 +02:00
Settings.TEMPLATE_FOLDERNAME_NRPC_SERVER = os.Getenv("TEMPLATE_FOLDERNAME_NRPC_SERVER")
Settings.TEMPLATE_FOLDERNAME_NRPC_CLIENT = os.Getenv("TEMPLATE_FOLDERNAME_NRPC_CLIENT")
2023-10-24 17:03:04 +02:00
Settings.TEXT_TEMPLATE_MODEL = os.Getenv("TEXT_TEMPLATE_MODEL")
Settings.TEXT_TEMPLATE_TABLENAME = os.Getenv("TEXT_TEMPLATE_TABLENAME")
2023-10-26 13:18:38 +02:00
Settings.TEMPLATE_SERVICE_NAME = os.Getenv("TEMPLATE_SERVICE_NAME")
2023-10-26 16:03:50 +02:00
Settings.TEMPLATE_FOLDERNAME_CRUD_STARTER = os.Getenv("TEMPLATE_FOLDERNAME_CRUD_STARTER")
Settings.SERVICE_REPOSITORY_URL = os.Getenv("SERVICE_REPOSITORY_URL")
2023-10-25 13:52:49 +02:00
sHAS_IS_DELETED := os.Getenv("HAS_IS_DELETED")
2023-09-28 16:45:44 +02:00
2023-10-06 15:48:58 +02:00
sNEED_CRUD := os.Getenv("NEED_CRUD")
Settings.NEED_CRUD = BoolFromString(sNEED_CRUD)
sNEED_GRPC := os.Getenv("NEED_GRPC")
Settings.NEED_GRPC = BoolFromString(sNEED_GRPC)
sNEED_NRPC := os.Getenv("NEED_NRPC")
Settings.NEED_NRPC = BoolFromString(sNEED_NRPC)
Settings.SERVICE_NAME = os.Getenv("SERVICE_NAME")
2023-11-01 16:34:57 +02:00
Settings.READY_FOLDERNAME = strings.ToLower(Settings.SERVICE_NAME)
2023-10-06 15:48:58 +02:00
2023-10-23 17:09:55 +02:00
if Settings.TEMPLATE_FOLDERNAME == "" {
log.Panic("Need fill TEMPLATE_FOLDERNAME")
}
2023-10-24 17:03:04 +02:00
if Settings.TEXT_TEMPLATE_MODEL == "" {
Settings.TEXT_TEMPLATE_MODEL = "LawsuitStatusType"
}
if Settings.TEXT_TEMPLATE_TABLENAME == "" {
Settings.TEXT_TEMPLATE_TABLENAME = "lawsuit_status_types"
}
2023-10-25 13:52:49 +02:00
HAS_IS_DELETED := BoolFromString(sHAS_IS_DELETED)
Settings.HAS_IS_DELETED = HAS_IS_DELETED
2023-09-28 16:45:44 +02:00
}
// CurrentDirectory - возвращает текущую директорию ОС
func CurrentDirectory() string {
Otvet, err := os.Getwd()
if err != nil {
//log.Println(err)
}
return Otvet
}
// FillFlags - заполняет параметры из командной строки
func FillFlags() {
Args := os.Args[1:]
if len(Args) > 1 {
return
}
}
2023-10-06 15:48:58 +02:00
// BoolFromString - возвращает true если строка = true, или =1
func BoolFromString(s string) bool {
Otvet := false
s = strings.TrimLeft(s, " ")
s = strings.TrimRight(s, " ")
s = strings.ToLower(s)
if s == "true" || s == "1" {
Otvet = true
}
return Otvet
}