移除无用代码

This commit is contained in:
李运家 2024-06-06 15:02:01 +08:00
parent 0a40e7ebbc
commit 73ba894e7e
8 changed files with 3 additions and 82 deletions

View File

@ -1 +1 @@
pub mod login_cache; pub mod account_cache;

View File

@ -1,39 +0,0 @@
// use std::collections::HashMap;
// use moka::future::Cache;
//
//
// use std::any::{Any, TypeId};
// use std::collections::HashMap;
// use std::lazy::SyncLazy;
// use moka::sync::Cache;
//
// type CacheKey = String;
//
// // 全局缓存,键为 String值为 Box<dyn Any>
// static GLOBAL_CACHE: SyncLazy<HashMap<TypeId, Cache<CacheKey, Box<dyn Any>>>> = SyncLazy::new(|| {
// HashMap::new()
// });
//
// fn insert<T: 'static + Any>(key: CacheKey, value: T) {
// let cache_type_id = TypeId::of::<T>();
// let mut cache = GLOBAL_CACHE.entry(cache_type_id).or_insert_with(|| {
// let config = moka::Config::builder().max_capacity(1000).build();
// Cache::with_config(config)
// });
// cache.insert(key, Box::new(value));
// }
//
// fn get<T: 'static + Any>(key: CacheKey) -> Option<T> {
// let cache_type_id = TypeId::of::<T>();
// GLOBAL_CACHE.get(&cache_type_id)?.get(&key)?.downcast::<T>().ok()
// }
//
// fn main() {
// insert("int_key".into(), 42);
// let int_value: Option<i32> = get("int_key".into());
// println!("Integer value: {:?}", int_value);
//
// insert("string_key".into(), "hello".to_string());
// let string_value: Option<String> = get("string_key".into());
// println!("String value: {:?}", string_value);
// }

View File

@ -1,4 +1,3 @@
pub mod config; pub mod config;
pub mod logger; pub mod logger;
pub mod db; pub mod db;
pub mod local_cache;

View File

@ -2,7 +2,7 @@ use axum::{extract::Request, middleware::Next, response::{IntoResponse, Response
use http::{header, StatusCode}; use http::{header, StatusCode};
use jsonwebtoken::{decode, DecodingKey, Validation}; use jsonwebtoken::{decode, DecodingKey, Validation};
use crate::{cache::login_cache::LOGIN_CACHE, config, token::Claims}; use crate::{cache::account_cache::LOGIN_CACHE, config, token::Claims};
const WHITE_LIST: &[(&str, &str)] = &[ const WHITE_LIST: &[(&str, &str)] = &[
("GET", "/api/v1/users/:id"), ("GET", "/api/v1/users/:id"),

View File

@ -1,4 +1,3 @@
pub mod rejection;
pub mod response; pub mod response;
pub mod status; pub mod status;
pub mod pageable; pub mod pageable;

View File

@ -1,34 +0,0 @@
use axum::{
extract::rejection::JsonRejection,
response::{IntoResponse, Response},
};
use axum_extra::extract::WithRejection;
use thiserror::Error;
use super::response::ResErr;
#[derive(Debug, Error)]
pub enum MyRejection {
// The `#[from]` attribute generates `From<JsonRejection> for MyRejection`
// implementation. See `thiserror` docs for more information
#[error(transparent)]
JSONExtractor(#[from] JsonRejection),
}
// We implement `IntoResponse` so MyRejection can be used as a response
impl IntoResponse for MyRejection {
fn into_response(self) -> Response {
let err = match self {
MyRejection::JSONExtractor(x) => match x {
JsonRejection::JsonDataError(e) => ResErr::ErrData(Some(e.body_text())),
JsonRejection::JsonSyntaxError(e) => ResErr::ErrData(Some(e.body_text())),
JsonRejection::MissingJsonContentType(e) => ResErr::ErrData(Some(e.body_text())),
_ => ResErr::ErrSystem(None),
},
};
err.into_response()
}
}
pub type IRejection<T> = WithRejection<T, MyRejection>;

View File

@ -156,11 +156,7 @@ impl Display for ResErr {
} }
} }
impl StdError for ResErr { impl StdError for ResErr {}
fn source(&self) -> Option<&(dyn StdError + 'static)> {
self.source()
}
}
impl From<String> for ResErr { impl From<String> for ResErr {
fn from(value: String) -> Self { fn from(value: String) -> Self {