diff --git a/crates/api-grub/Cargo.toml b/crates/api-grub/Cargo.toml index dab7e76..287df71 100644 --- a/crates/api-grub/Cargo.toml +++ b/crates/api-grub/Cargo.toml @@ -10,3 +10,5 @@ tokio = { version = "1.43.0", features = ["full"] } integr-structs = {path = "../integr-structs"} env_logger = "0.11.6" log = "0.4.25" +anyhow = "1.0.95" +chrono = "0.4.39" diff --git a/crates/api-grub/config.json b/crates/api-grub/config.json index 82e9c89..f73fd93 100644 --- a/crates/api-grub/config.json +++ b/crates/api-grub/config.json @@ -1,4 +1,5 @@ { "api-endpoint" : "http://127.0.0.1:8081/ping", - "method" : "GET" + "method" : "GET", + "delay" : "5" } \ No newline at end of file diff --git a/crates/api-grub/src/config.rs b/crates/api-grub/src/config.rs index a785a84..3455016 100644 --- a/crates/api-grub/src/config.rs +++ b/crates/api-grub/src/config.rs @@ -1,2 +1,14 @@ // mod to communicate with api-grub config file -// 1) check changes in unix-socket \ No newline at end of file +// 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() {} \ No newline at end of file diff --git a/crates/api-grub/src/logger.rs b/crates/api-grub/src/logger.rs new file mode 100644 index 0000000..523fafb --- /dev/null +++ b/crates/api-grub/src/logger.rs @@ -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(()) +} \ No newline at end of file diff --git a/crates/api-grub/src/main.rs b/crates/api-grub/src/main.rs index 2a04848..9bff6d7 100644 --- a/crates/api-grub/src/main.rs +++ b/crates/api-grub/src/main.rs @@ -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")] -async fn main() { - println!("Hello, world!"); +async fn main() -> Result<()>{ + // 3 coroutines + // 1) unix-socket coroutine (for config updating) + // 2) api coroutine + // 3) ? + setup_logger()?; + info!("Logger configured"); + Ok(()) } diff --git a/crates/api-grub/src/net.rs b/crates/api-grub/src/net.rs new file mode 100644 index 0000000..d05fd78 --- /dev/null +++ b/crates/api-grub/src/net.rs @@ -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() { + +} + diff --git a/crates/integr-structs/src/api.rs b/crates/integr-structs/src/api.rs index e69de29..e8c66d3 100644 --- a/crates/integr-structs/src/api.rs +++ b/crates/integr-structs/src/api.rs @@ -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, + } + } +} \ No newline at end of file