Moved structs into their own file.

This commit is contained in:
shad0wflame 2021-12-22 19:45:20 +01:00
parent 504fc87b83
commit c39b0e898a
4 changed files with 63 additions and 10 deletions

View File

@ -0,0 +1,47 @@
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize)]
pub struct DNSRecordsHolder {
pub records: Vec<DNSRecord>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct DNSRecord {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub record_type: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub data: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub port: Option<u16>, // SRV Only.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub priority: Option<u32>, // MX and SRV only.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub protocol: Option<String>, // SRV only.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub service: Option<String>, // SRV only.
pub ttl: u32,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub interpolate: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub weight: Option<u32>, // SRV only.
}

6
src/ip_handler/ip.rs Normal file
View File

@ -0,0 +1,6 @@
use serde::Deserialize;
#[derive(Deserialize)]
pub struct IP {
pub origin: String,
}

View File

@ -1,17 +1,16 @@
use serde::Deserialize;
use std::fs::{read_to_string, File};
use std::fs::{File, read_to_string};
use std::io::Write;
use std::path::Path;
use log::debug;
use crate::ip_handler::ip::IP;
mod ip;
const IP_FILE_NAME: &'static str = "ddns_ip";
const WEBSITE_URL: &'static str = "https://httpbin.org/ip";
#[derive(Deserialize)]
struct IP {
origin: String,
}
/// Returns an Option holding the current IP address if the value has changed, otherwise returns None.
pub async fn get_ip_to_publish() -> Option<String> {
let previous_ip = match check_previous_ip() {

View File

@ -1,9 +1,10 @@
mod go_daddy_ddns;
mod ip_handler;
use std::env;
use log::LevelFilter;
use simple_logger::SimpleLogger;
use std::env;
mod go_daddy_ddns;
mod ip_handler;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {