2023-10-24 17:03:04 +02:00
|
|
|
package load_configs
|
|
|
|
|
|
|
|
import (
|
2023-10-27 10:43:15 +02:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2023-10-24 17:03:04 +02:00
|
|
|
"github.com/ManyakRus/crud_generator/internal/config"
|
2023-11-15 12:58:31 +02:00
|
|
|
"github.com/ManyakRus/crud_generator/internal/constants"
|
2023-11-02 17:19:33 +02:00
|
|
|
"github.com/ManyakRus/crud_generator/internal/create_files"
|
2023-10-27 10:43:15 +02:00
|
|
|
"github.com/ManyakRus/crud_generator/internal/types"
|
2023-10-24 17:03:04 +02:00
|
|
|
"github.com/ManyakRus/crud_generator/pkg/dbmeta"
|
|
|
|
"github.com/ManyakRus/starter/log"
|
|
|
|
"github.com/ManyakRus/starter/micro"
|
2023-10-27 10:43:15 +02:00
|
|
|
"os"
|
2023-10-24 17:03:04 +02:00
|
|
|
)
|
|
|
|
|
2023-10-27 10:43:15 +02:00
|
|
|
func LoadConfigsAll() {
|
|
|
|
LoadMappings()
|
|
|
|
LoadNameReplace()
|
2023-11-02 17:19:33 +02:00
|
|
|
LoadNullable()
|
|
|
|
Load_TEXT_DB_MODIFIED_AT()
|
2023-12-25 16:15:24 +02:00
|
|
|
Load_TEXT_DB_CREATED_AT()
|
2023-11-02 17:19:33 +02:00
|
|
|
Load_TEXT_DB_IS_DELETED()
|
2023-11-07 16:58:02 +02:00
|
|
|
LoadConvertID()
|
2023-11-29 10:21:05 +02:00
|
|
|
LoadMapModelCrudDeleteFunctions()
|
2024-01-09 12:48:10 +02:00
|
|
|
LoadCrudFunctionsRename()
|
2023-10-27 10:43:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// LoadMappings - загружает маппинг ТипБД = ТипGolang, из файла .json
|
|
|
|
func LoadMappings() {
|
2023-10-24 17:03:04 +02:00
|
|
|
dir := micro.ProgramDir_bin()
|
2023-11-15 12:58:31 +02:00
|
|
|
FileName := dir + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile() + constants.CONFIG_FOLDER_NAME + micro.SeparatorFile() + "mapping.json"
|
2023-10-27 10:43:15 +02:00
|
|
|
err := dbmeta.LoadMappings(FileName, false)
|
2023-10-24 17:03:04 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Panic("LoadMappings() error: ", err)
|
|
|
|
}
|
|
|
|
}
|
2023-10-27 10:43:15 +02:00
|
|
|
|
|
|
|
// LoadNameReplace - загружает маппинг ТипБД = ТипGolang, из файла .json
|
|
|
|
func LoadNameReplace() {
|
|
|
|
dir := micro.ProgramDir_bin()
|
2024-02-16 10:37:36 +02:00
|
|
|
FileName := dir + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile() + constants.CONFIG_FOLDER_NAME + micro.SeparatorFile() + config.Settings.TEMPLATES_NAME_REPLACE_FILENAME
|
2023-10-27 10:43:15 +02:00
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
//чтение файла
|
|
|
|
bytes, err := os.ReadFile(FileName)
|
|
|
|
if err != nil {
|
|
|
|
TextError := fmt.Sprint("ReadFile() error: ", err)
|
|
|
|
log.Panic(TextError)
|
|
|
|
}
|
|
|
|
|
|
|
|
//json в map
|
|
|
|
//var MapServiceURL2 = make(map[string]string)
|
|
|
|
err = json.Unmarshal(bytes, &types.MapReplaceName)
|
|
|
|
if err != nil {
|
|
|
|
log.Panic("Unmarshal() error: ", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-11-02 17:19:33 +02:00
|
|
|
|
|
|
|
// LoadNullable - загружает список полей которые могут быть null
|
|
|
|
func LoadNullable() {
|
|
|
|
dir := micro.ProgramDir_bin()
|
2024-02-16 10:37:36 +02:00
|
|
|
FileName := dir + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile() + constants.CONFIG_FOLDER_NAME + micro.SeparatorFile() + config.Settings.TEMPLATES_NULLABLE_FILENAME
|
2023-11-02 17:19:33 +02:00
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
//чтение файла
|
|
|
|
bytes, err := os.ReadFile(FileName)
|
|
|
|
if err != nil {
|
|
|
|
TextError := fmt.Sprint("ReadFile() error: ", err)
|
|
|
|
log.Panic(TextError)
|
|
|
|
}
|
|
|
|
|
|
|
|
//json в map
|
|
|
|
//var MapServiceURL2 = make(map[string]string)
|
|
|
|
err = json.Unmarshal(bytes, &types.MapNullableFileds)
|
|
|
|
if err != nil {
|
|
|
|
log.Panic("Unmarshal() error: ", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load_TEXT_DB_MODIFIED_AT - загружает текст DB_MODIFIED_AT
|
|
|
|
func Load_TEXT_DB_MODIFIED_AT() {
|
|
|
|
DirTemplatesDB := create_files.Find_Template_DB_Foldername()
|
|
|
|
FileName := DirTemplatesDB + "modified_at.go_"
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
//чтение файла
|
|
|
|
bytes, err := os.ReadFile(FileName)
|
|
|
|
if err != nil {
|
|
|
|
TextError := fmt.Sprint("ReadFile() error: ", err)
|
|
|
|
log.Error(TextError)
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Settings.TEXT_DB_MODIFIED_AT = string(bytes)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load_TEXT_DB_IS_DELETED - загружает текст DB_IS_DELETED
|
|
|
|
func Load_TEXT_DB_IS_DELETED() {
|
|
|
|
DirTemplatesDB := create_files.Find_Template_DB_Foldername()
|
|
|
|
FileName := DirTemplatesDB + "is_deleted.go_"
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
//чтение файла
|
|
|
|
bytes, err := os.ReadFile(FileName)
|
|
|
|
if err != nil {
|
|
|
|
TextError := fmt.Sprint("ReadFile() error: ", err)
|
|
|
|
log.Error(TextError)
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Settings.TEXT_DB_IS_DELETED = string(bytes)
|
|
|
|
|
|
|
|
}
|
2023-11-07 16:58:02 +02:00
|
|
|
|
|
|
|
// LoadConvertID - загружает map: ИмяТаблицы:Тип
|
|
|
|
func LoadConvertID() {
|
|
|
|
dir := micro.ProgramDir_bin()
|
2024-02-16 10:37:36 +02:00
|
|
|
FileName := dir + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile() + constants.CONFIG_FOLDER_NAME + micro.SeparatorFile() + config.Settings.TEMPLATES_CONVERT_ID_FILENAME
|
2023-11-07 16:58:02 +02:00
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
//чтение файла
|
|
|
|
bytes, err := os.ReadFile(FileName)
|
|
|
|
if err != nil {
|
|
|
|
TextError := fmt.Sprint("ReadFile() error: ", err)
|
|
|
|
log.Panic(TextError)
|
|
|
|
}
|
|
|
|
|
|
|
|
//json в map
|
|
|
|
//var MapServiceURL2 = make(map[string]string)
|
|
|
|
err = json.Unmarshal(bytes, &types.MapConvertID)
|
|
|
|
if err != nil {
|
|
|
|
log.Panic("Unmarshal() error: ", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-11-29 10:21:05 +02:00
|
|
|
|
|
|
|
// LoadMapModelCrudDeleteFunctions - загружает map ИмяТаблицыPostgres:ИмяФункцииGolang
|
|
|
|
func LoadMapModelCrudDeleteFunctions() {
|
|
|
|
dir := micro.ProgramDir_bin()
|
2024-02-16 10:37:36 +02:00
|
|
|
FileName := dir + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile() + constants.CONFIG_FOLDER_NAME + micro.SeparatorFile() + config.Settings.TEMPLATES_MODEL_CRUD_DELETE_FUNCTIONS_FILENAME
|
2023-11-29 10:21:05 +02:00
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
//чтение файла
|
|
|
|
bytes, err := os.ReadFile(FileName)
|
|
|
|
if err != nil {
|
|
|
|
TextError := fmt.Sprint("ReadFile() error: ", err)
|
|
|
|
log.Panic(TextError)
|
|
|
|
}
|
|
|
|
|
|
|
|
//json в map
|
|
|
|
//var MapServiceURL2 = make(map[string]string)
|
|
|
|
err = json.Unmarshal(bytes, &types.MapModelCrudDeleteFunctions)
|
|
|
|
if err != nil {
|
|
|
|
log.Panic("Unmarshal() error: ", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-12-25 16:15:24 +02:00
|
|
|
|
|
|
|
// Load_TEXT_DB_CREATED_AT - загружает текст created_at.go_
|
|
|
|
func Load_TEXT_DB_CREATED_AT() {
|
|
|
|
DirTemplatesDB := create_files.Find_Template_DB_Foldername()
|
|
|
|
FileName := DirTemplatesDB + "created_at.go_"
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
//чтение файла
|
|
|
|
bytes, err := os.ReadFile(FileName)
|
|
|
|
if err != nil {
|
|
|
|
TextError := fmt.Sprint("ReadFile() error: ", err)
|
|
|
|
log.Error(TextError)
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Settings.TEXT_DB_CREATED_AT = string(bytes)
|
|
|
|
|
|
|
|
}
|
2024-01-09 12:48:10 +02:00
|
|
|
|
|
|
|
// LoadCrudFunctionsRename - загружает маппинг ИмяТаблицы:{old:"",new:""}
|
|
|
|
func LoadCrudFunctionsRename() {
|
|
|
|
dir := micro.ProgramDir_bin()
|
2024-02-16 10:37:36 +02:00
|
|
|
FileName := dir + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile() + constants.CONFIG_FOLDER_NAME + micro.SeparatorFile() + config.Settings.TEMPLATES_CRUD_FUNCTIONS_RENAME_FILENAME
|
2024-01-09 12:48:10 +02:00
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
//чтение файла
|
|
|
|
bytes, err := os.ReadFile(FileName)
|
|
|
|
if err != nil {
|
|
|
|
TextError := fmt.Sprint("ReadFile() error: ", err)
|
|
|
|
log.Panic(TextError)
|
|
|
|
}
|
|
|
|
|
|
|
|
//json в map
|
|
|
|
//var MapServiceURL2 = make(map[string]string)
|
|
|
|
err = json.Unmarshal(bytes, &types.MapRenameFunctions)
|
|
|
|
if err != nil {
|
|
|
|
log.Panic("Unmarshal() error: ", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|