use crate::rubase::ruconst::ruconst;
use crate::rulog::rulog;
use serde::Deserialize;
use spicex::Spice;
use std::fs::File;
use std::io::{BufReader, Read};
use crate::rubase::rudto::cfgdto;
use crate::rubase::rutils::strutils;
const fn ini() -> i32 {
return 1;
}
pub static I: i32 = ini();
#[derive(Deserialize, Debug)]
struct DatabaseConfig {
host: String,
port: u16,
}
impl DatabaseConfig {
pub fn new(host: &str, port: u16) -> Self {
DatabaseConfig {
host: host.to_owned(),
port: port,
}
}
}
#[derive(Deserialize, Debug)]
struct AppConfig {
database: DatabaseConfig,
debug: bool,
}
impl AppConfig {
pub fn new(database: DatabaseConfig, debug: bool) -> AppConfig {
AppConfig { database, debug }
}
}
pub fn parse_env() -> String {
let mut spice = Spice::new();
spice.set_config_file(ruconst::FILE_PATH_ENV).unwrap();
let env = spice.get_string("Env").unwrap();
return env.unwrap();
}
pub fn exist_env(var: &str) -> bool {
var.contains("$")
}
pub fn parse_env_var(var: String) -> String {
return strutils::parse_env_var(var);
}
pub fn parse_env2file() -> String {
let env_file = parse_env();
let filename = String::from("ichub-") + &parse_env_var(env_file) + ".yml";
rulog::info(filename.as_str());
return filename;
}
pub fn parse_cfg2file(fileName: String) -> String {
let mut spice = Spice::new();
let filepath = String::from("./config/") + &fileName;
spice.set_config_file(filepath).unwrap();
let env = spice.get_string("software.env").unwrap();
return parse_env_var(env.unwrap());
}
pub fn parse_config() {
let file = File::open("./config/ichub-postgres.yml");
let mut read = BufReader::new(file.unwrap());
let mut yaml_str = String::new();
read.read_to_string(&mut yaml_str).unwrap();
let ret = serde_yaml::from_str::<cfgdto::cfgdto::CfgDto>(&yaml_str);
println!("{:#?}", ret);
}