zero4rs 2.0.0

zero4rs is a powerful, pragmatic, and extremely fast web framework for Rust
Documentation
include!(concat!(env!("OUT_DIR"), "/build_info.rs"));

use chrono::TimeZone;
use chrono::{DateTime, Utc};
use std::env;
use crate::commons::date_string;

pub fn cargo_version() -> String {
    let v = rustc_version_runtime::version();

    format!("{}.{}.{}", v.major, v.minor, v.patch)
}

pub fn cargo_channel() -> String {
    match rustc_version_runtime::version_meta().channel {
        rustc_version::Channel::Stable => "stable".to_string(),
        rustc_version::Channel::Beta => "beta".to_string(),
        rustc_version::Channel::Nightly => "nightly".to_string(),
        rustc_version::Channel::Dev => "dev".to_string(),
    }
}

pub fn cargo_commit() -> String {
    let hash = rustc_version_runtime::version_meta()
        .commit_hash
        .unwrap_or_else(|| "N/a".to_string());
    let date = rustc_version_runtime::version_meta()
        .commit_date
        .unwrap_or_else(|| "N/a".to_string());

    format!("({} {})", &hash[0..10], date)
}

pub fn git_version() -> String {
    println!("{} STDOUT [{}:{}] - {}", date_string(), module_path!(), line!(), format!(
        "Git version: {}, GIT_VERSION={}",
        concat!(env!("OUT_DIR"), "/build_info.rs"),
        GIT_VERSION
    ));

    GIT_VERSION.trim().to_string()
}

pub fn author() -> String {
    MAIN_AUTHOR.trim().to_string()
}

// 当前程序的执行路径
pub fn bin_path() -> String {
    match env::current_exe() {
        Ok(path) => match path.to_str() {
            Some(path_str) => path_str.to_owned(),
            None => "N/a".to_string(),
        },
        Err(_) => "N/a".to_string(),
    }
}

pub fn time() -> String {
    // BUILDING_TIME.to_string()
    let unix_timestamp = BUILDING_TIME;
    let datetime_utc = Utc.timestamp_opt(unix_timestamp, 0);
    format_datetime(&datetime_utc.unwrap())
}

pub fn timestamp() -> String {
    format!("{}", BUILDING_TIME)
}

pub fn os() -> String {
    let os = TARGET_OS.to_string().trim().to_string();

    if os == "Linux Linux" {
        "Linux".to_string()
    } else {
        os
    }
}

pub fn arch() -> String {
    TARGET_ARCH.to_string().trim().to_string()
}

pub fn cargo_line() {
    println!("{} STDOUT [{}:{}] - {}", date_string(), module_path!(), line!(), format!(
        "cargo {}-{} {}",
        cargo_version(),
        cargo_channel(),
        cargo_commit()
    ));
}

pub fn line() {
    let gt = git_version();

    let l1 = if gt.is_empty() {
        "None"
    } else {
        &format!("+{}", &gt)
    };

    println!("{} STDOUT [{}:{}] - {}", date_string(), module_path!(), line!(), format!(
        "{} {} '{}' ({}, {})",
        bin_path(),
        os(),
        arch(),
        l1,
        time()
    ));
}

fn format_datetime(datetime: &DateTime<Utc>) -> String {
    format_date(datetime).to_string()
}

fn format_date(datetime: &DateTime<Utc>) -> String {
    datetime.format("%b-%d-%Y").to_string()
}