pre-format version strings
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
7638bbc49c
commit
3a51e18ce6
7 changed files with 32 additions and 32 deletions
|
@ -145,7 +145,7 @@ pub(crate) async fn syncv3_client_server_json() -> Result<impl IntoResponse> {
|
|||
|
||||
Ok(Json(serde_json::json!({
|
||||
"server": server_url,
|
||||
"version": conduit::version::conduwuit(),
|
||||
"version": conduit::version(),
|
||||
})))
|
||||
}
|
||||
|
||||
|
@ -155,8 +155,8 @@ pub(crate) async fn syncv3_client_server_json() -> Result<impl IntoResponse> {
|
|||
/// `/_matrix/federation/v1/version`
|
||||
pub(crate) async fn conduwuit_server_version() -> Result<impl IntoResponse> {
|
||||
Ok(Json(serde_json::json!({
|
||||
"name": "conduwuit",
|
||||
"version": conduit::version::conduwuit(),
|
||||
"name": conduit::version::name(),
|
||||
"version": conduit::version::version(),
|
||||
})))
|
||||
}
|
||||
|
||||
|
|
|
@ -10,8 +10,8 @@ pub(crate) async fn get_server_version_route(
|
|||
) -> Result<get_server_version::v1::Response> {
|
||||
Ok(get_server_version::v1::Response {
|
||||
server: Some(get_server_version::v1::Server {
|
||||
name: Some("Conduwuit".to_owned()),
|
||||
version: Some(conduit::version::conduwuit()),
|
||||
name: Some(conduit::version::name().into()),
|
||||
version: Some(conduit::version::version().into()),
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ pub use config::Config;
|
|||
pub use error::{Error, RumaResponse};
|
||||
pub use pducount::PduCount;
|
||||
pub use server::Server;
|
||||
pub use version::version;
|
||||
|
||||
pub type Result<T, E = Error> = std::result::Result<T, E>;
|
||||
|
||||
|
|
|
@ -4,25 +4,28 @@
|
|||
/// Set the environment variable `CONDUWUIT_VERSION_EXTRA` to any UTF-8 string
|
||||
/// to include it in parenthesis after the SemVer version. A common value are
|
||||
/// git commit hashes.
|
||||
use std::sync::OnceLock;
|
||||
|
||||
static BRANDING: &str = "Conduwuit";
|
||||
static SEMANTIC: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
static VERSION: OnceLock<String> = OnceLock::new();
|
||||
static USER_AGENT: OnceLock<String> = OnceLock::new();
|
||||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn conduwuit() -> String {
|
||||
match option_env!("CONDUWUIT_VERSION_EXTRA") {
|
||||
Some(extra) => {
|
||||
if extra.is_empty() {
|
||||
env!("CARGO_PKG_VERSION").to_owned()
|
||||
} else {
|
||||
format!("{} ({})", env!("CARGO_PKG_VERSION"), extra)
|
||||
}
|
||||
},
|
||||
None => match option_env!("CONDUIT_VERSION_EXTRA") {
|
||||
Some(extra) => {
|
||||
if extra.is_empty() {
|
||||
env!("CARGO_PKG_VERSION").to_owned()
|
||||
} else {
|
||||
format!("{} ({})", env!("CARGO_PKG_VERSION"), extra)
|
||||
}
|
||||
},
|
||||
None => env!("CARGO_PKG_VERSION").to_owned(),
|
||||
},
|
||||
}
|
||||
pub fn name() -> &'static str { BRANDING }
|
||||
|
||||
#[inline]
|
||||
pub fn version() -> &'static str { VERSION.get_or_init(init_version) }
|
||||
|
||||
#[inline]
|
||||
pub fn user_agent() -> &'static str { USER_AGENT.get_or_init(init_user_agent) }
|
||||
|
||||
fn init_user_agent() -> String { format!("{}/{}", name(), version()) }
|
||||
|
||||
fn init_version() -> String {
|
||||
option_env!("CONDUWUIT_VERSION_EXTRA")
|
||||
.or(option_env!("CONDUIT_VERSION_EXTRA"))
|
||||
.map_or(SEMANTIC.to_owned(), |extra| format!("{BRANDING} ({extra})"))
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use clap::Parser;
|
|||
|
||||
/// Commandline arguments
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(version = conduit::version::conduwuit(), about, long_about = None)]
|
||||
#[clap(version = conduit::version(), about, long_about = None)]
|
||||
pub(crate) struct Args {
|
||||
#[arg(short, long)]
|
||||
/// Optional argument to the path of a conduwuit config TOML file
|
||||
|
|
|
@ -46,7 +46,7 @@ impl Server {
|
|||
database_path = ?config.database_path,
|
||||
log_levels = %config.log,
|
||||
"{}",
|
||||
conduit::version::conduwuit(),
|
||||
conduit::version(),
|
||||
);
|
||||
|
||||
Ok(Arc::new(Self {
|
||||
|
|
|
@ -87,10 +87,6 @@ impl Client {
|
|||
}
|
||||
|
||||
fn base(config: &Config) -> Result<reqwest::ClientBuilder> {
|
||||
let version = conduit::version::conduwuit();
|
||||
|
||||
let user_agent = format!("Conduwuit/{version}");
|
||||
|
||||
let mut builder = reqwest::Client::builder()
|
||||
.hickory_dns(true)
|
||||
.connect_timeout(Duration::from_secs(config.request_conn_timeout))
|
||||
|
@ -98,7 +94,7 @@ impl Client {
|
|||
.timeout(Duration::from_secs(config.request_total_timeout))
|
||||
.pool_idle_timeout(Duration::from_secs(config.request_idle_timeout))
|
||||
.pool_max_idle_per_host(config.request_idle_per_host.into())
|
||||
.user_agent(user_agent)
|
||||
.user_agent(conduit::version::user_agent())
|
||||
.redirect(redirect::Policy::limited(6))
|
||||
.connection_verbose(true);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue