pub(crate) mod manifest;
pub(crate) mod resolve;
pub(crate) use manifest::GoRelease;
pub(crate) use resolve::{compare_versions, resolve_version};
use std::path::PathBuf;
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) struct GoVersion {
pub(crate) raw_version: String,
pub(crate) display_name: String,
pub(crate) filename: String,
pub(crate) url: String,
pub(crate) size: u64,
pub(crate) installed: bool,
pub(crate) active: bool,
pub(crate) path: Option<PathBuf>,
pub(crate) stable: bool,
}
impl GoVersion {
#[must_use]
pub(crate) fn prerelease_tag(raw: &str) -> Option<String> {
let tag = raw.split('.').find_map(|part| {
let idx = part.find(|c: char| c.is_ascii_alphabetic())?;
Some(part[idx..].trim())
})?;
if tag.is_empty() {
None
} else {
Some(tag.to_string())
}
}
#[must_use]
pub(crate) fn format_size(bytes: u64) -> String {
const UNITS: [&str; 4] = ["B", "KB", "MB", "GB"];
#[allow(clippy::cast_precision_loss)]
let mut value = bytes as f64;
let mut unit = 0;
while value >= 1024.0 && unit < UNITS.len() - 1 {
value /= 1024.0;
unit += 1;
}
if unit == 0 {
format!("{} {}", bytes, UNITS[unit])
} else {
format!("{:.1} {}", value, UNITS[unit])
}
}
}