Rewrite as an object
This commit is contained in:
parent
79102ba463
commit
00c2039034
4 changed files with 22 additions and 22 deletions
|
@ -1,5 +1,5 @@
|
||||||
use std::env;
|
use std::env;
|
||||||
use anyhow::{Result, Context, Error, anyhow};
|
use anyhow::{Result, Context, anyhow};
|
||||||
use log::*;
|
use log::*;
|
||||||
|
|
||||||
pub struct DiplonatConfig {
|
pub struct DiplonatConfig {
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
use anyhow::{Result, Context};
|
use anyhow::{Result, Context};
|
||||||
use log::*;
|
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
pub struct DiplonatContext {
|
pub struct Diplonat {
|
||||||
pub config: config::DiplonatConfig,
|
pub config: config::DiplonatConfig,
|
||||||
pub gateway: igd::aio::Gateway
|
pub gateway: igd::aio::Gateway
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn setup() -> Result<DiplonatContext> {
|
impl Diplonat {
|
||||||
let ctx = DiplonatContext {
|
pub async fn new() -> Result<Self> {
|
||||||
|
let ctx = Self {
|
||||||
config: config::load_env().context("Unable to read configuration from environment")?,
|
config: config::load_env().context("Unable to read configuration from environment")?,
|
||||||
gateway: gw::get_gateway().await?
|
gateway: gw::get_gateway().await?
|
||||||
};
|
};
|
||||||
|
@ -16,6 +16,7 @@ pub async fn setup() -> Result<DiplonatContext> {
|
||||||
return Ok(ctx);
|
return Ok(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn listen() -> bool {
|
pub fn listen(&self) -> bool {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use igd::aio::Gateway;
|
|
||||||
use igd::aio::search_gateway;
|
use igd::aio::search_gateway;
|
||||||
use anyhow::{Result, Context};
|
use anyhow::{Result, Context};
|
||||||
use log::*;
|
use log::*;
|
||||||
|
|
18
src/main.rs
18
src/main.rs
|
@ -1,20 +1,20 @@
|
||||||
use std::net::SocketAddrV4;
|
|
||||||
//use std::collections::HashMap;
|
|
||||||
|
|
||||||
use log::*;
|
|
||||||
|
|
||||||
use igd::PortMappingProtocol;
|
|
||||||
|
|
||||||
mod diplonat;
|
mod diplonat;
|
||||||
mod config;
|
mod config;
|
||||||
mod gw;
|
mod gw;
|
||||||
|
|
||||||
|
//use std::net::SocketAddrV4;
|
||||||
|
//use std::collections::HashMap;
|
||||||
|
//use igd::PortMappingProtocol;
|
||||||
|
use log::*;
|
||||||
|
use diplonat::*;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
pretty_env_logger::init();
|
pretty_env_logger::init();
|
||||||
|
info!("Starting Diplonat");
|
||||||
|
|
||||||
let ctx = diplonat::setup().await.expect("Setup failed");
|
let diplo = Diplonat::new().await.expect("Setup failed");
|
||||||
diplonat::listen();
|
diplo.listen();
|
||||||
/*
|
/*
|
||||||
let url = format!("http://127.0.0.1:8500/v1/catalog/node/{}", config.consul_node_name);
|
let url = format!("http://127.0.0.1:8500/v1/catalog/node/{}", config.consul_node_name);
|
||||||
let resp = reqwest::get(&url)
|
let resp = reqwest::get(&url)
|
||||||
|
|
Loading…
Reference in a new issue