perf: remove lazy_static
This commit is contained in:
+13
-14
@@ -4,29 +4,28 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
env_logger.workspace = true
|
||||
|
||||
tower-http = { workspace = true, features = ["cors"]}
|
||||
# Framework
|
||||
tokio.workspace = true
|
||||
tower-http = { workspace = true, features = ["cors"] }
|
||||
axum.workspace = true
|
||||
axum-server.workspace = true
|
||||
|
||||
lazy_static.workspace = true
|
||||
|
||||
# JSON
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
|
||||
tokio.workspace = true
|
||||
tokio-util.workspace = true
|
||||
|
||||
# Logging
|
||||
tracing.workspace = true
|
||||
tracing-futures.workspace = true
|
||||
tracing-log.workspace = true
|
||||
tracing-subscriber.workspace = true
|
||||
tracing-bunyan-formatter.workspace = true
|
||||
ansi_term.workspace = true
|
||||
env_logger.workspace = true
|
||||
|
||||
# Encoding / Serialization
|
||||
prost.workspace = true
|
||||
rbase64.workspace = true
|
||||
proto.workspace = true
|
||||
|
||||
# Error handling
|
||||
anyhow.workspace = true
|
||||
|
||||
# Local
|
||||
common.workspace = true
|
||||
proto.workspace = true
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
mod version_config;
|
||||
|
||||
pub use version_config::INSTANCE as versions;
|
||||
pub mod version_config;
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
use std::collections::HashMap;
|
||||
use std::{collections::HashMap, sync::OnceLock};
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use serde::Deserialize;
|
||||
use serde_json::from_str;
|
||||
|
||||
const DEFAULT_VERSIONS: &str = include_str!("../../versions.json");
|
||||
const DEFAULT_VERSIONS: &str = include_str!("../../../versions.json");
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct VersionConfig {
|
||||
@@ -14,16 +12,16 @@ pub struct VersionConfig {
|
||||
// pub lua_version: String,
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
pub static ref INSTANCE: HashMap<String, VersionConfig> = {
|
||||
let local_config = std::path::Path::new("versions.json");
|
||||
let data = if local_config.exists() {
|
||||
std::fs::read_to_string("versions.json").unwrap()
|
||||
} else {
|
||||
std::fs::write("versions.json", DEFAULT_VERSIONS).unwrap();
|
||||
DEFAULT_VERSIONS.to_string()
|
||||
};
|
||||
pub fn instance() -> &'static HashMap<String, VersionConfig> {
|
||||
static INSTANCE: OnceLock<HashMap<String, VersionConfig>> = OnceLock::new();
|
||||
INSTANCE.get_or_init(|| {
|
||||
const CONFIG_PATH: &str = "versions.json";
|
||||
|
||||
from_str(&data).unwrap()
|
||||
};
|
||||
let data = std::fs::read_to_string(CONFIG_PATH).unwrap_or_else(|_| {
|
||||
std::fs::write(CONFIG_PATH, DEFAULT_VERSIONS).expect("Failed to create versions file");
|
||||
DEFAULT_VERSIONS.to_string()
|
||||
});
|
||||
|
||||
serde_json::from_str(&data).unwrap_or_else(|e| panic!("Failed to parse versions.json: {e}"))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::config::versions;
|
||||
use crate::config::version_config;
|
||||
use axum::extract::Query;
|
||||
use prost::Message;
|
||||
use proto::{DispatchRegionData, Gateserver, RegionEntry};
|
||||
@@ -34,7 +34,7 @@ pub struct QueryGatewayParameters {
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn query_gateway(parameters: Query<QueryGatewayParameters>) -> String {
|
||||
let rsp = if let Some(config) = versions.get(¶meters.version) {
|
||||
let rsp = if let Some(config) = version_config::instance().get(¶meters.version) {
|
||||
Gateserver {
|
||||
retcode: 0,
|
||||
ip: String::from("127.0.0.1"),
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"OSBETAWin3.1.51": {
|
||||
"asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_9573347_b03981f01966",
|
||||
"ex_resource_url": "https://autopatchos.starrails.com/design_data/BetaLive/output_9589567_9c50629b0369",
|
||||
"lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_9567078_0e2b6acf6a2f",
|
||||
"ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_0_40d2ce0253"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user