struct changes

pull/3/head
prplV 2025-01-16 11:04:49 +03:00
parent aca94a9ad2
commit 60d325e4bf
7 changed files with 85 additions and 4 deletions

View File

@ -10,3 +10,5 @@ tokio = { version = "1.43.0", features = ["full"] }
integr-structs = {path = "../integr-structs"} integr-structs = {path = "../integr-structs"}
env_logger = "0.11.6" env_logger = "0.11.6"
log = "0.4.25" log = "0.4.25"
anyhow = "1.0.95"
chrono = "0.4.39"

View File

@ -1,4 +1,5 @@
{ {
"api-endpoint" : "http://127.0.0.1:8081/ping", "api-endpoint" : "http://127.0.0.1:8081/ping",
"method" : "GET" "method" : "GET",
"delay" : "5"
} }

View File

@ -1,2 +1,14 @@
// mod to communicate with api-grub config file // mod to communicate with api-grub config file
// 1) check changes in unix-socket // 1) check changes in unix-socket
// 2) save changes in local config file
use integr_structs::api::ApiConfig;
use tokio::net::UnixListener;
use anyhow::Result;
// for config pulling
async fn init_api_grub_mechanism(config: ApiConfig) {
}
async fn init_unix_listener() {}

View File

@ -0,0 +1,24 @@
use chrono::Local;
use env_logger::Builder;
use log::LevelFilter;
use std::io::Write;
use anyhow::Result;
pub fn setup_logger() -> Result<()> {
Builder::new()
.format(move |buf, record| {
writeln!(
buf,
"|{}| {} [{}] - {}",
"api-grubber",
Local::now().format("%d-%m-%Y %H:%M:%S"),
record.level(),
record.args(),
)
})
.filter(None, LevelFilter::Info)
.target(env_logger::Target::Stdout)
.init();
Ok(())
}

View File

@ -1,5 +1,18 @@
mod config;
mod net;
mod logger;
use anyhow::Result;
use logger::setup_logger;
use log::info;
#[tokio::main(flavor = "multi_thread")] #[tokio::main(flavor = "multi_thread")]
async fn main() { async fn main() -> Result<()>{
println!("Hello, world!"); // 3 coroutines
// 1) unix-socket coroutine (for config updating)
// 2) api coroutine
// 3) ?
setup_logger()?;
info!("Logger configured");
Ok(())
} }

View File

@ -0,0 +1,9 @@
// module to handle unix-socket connection + pulling info from api
use anyhow;
// for api info pulling
async fn init_api_grub_mechanism() {
}

View File

@ -0,0 +1,20 @@
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
pub struct ApiConfig {
url : String,
method : String,
delay : u32,
}
impl Default for ApiConfig {
fn default() -> Self {
ApiConfig {
url : String::new(),
method : String::new(),
delay : 0,
}
}
}