Skip to content

Commit

Permalink
refactor: fix some typo
Browse files Browse the repository at this point in the history
  • Loading branch information
zhu327 committed Dec 24, 2024
1 parent e547d7c commit 73359d0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
29 changes: 14 additions & 15 deletions src/admin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
};

#[async_trait]
trait Hanlder {
trait Handler {
async fn handle(
&self,
etcd: &EtcdClientWrapper,
Expand All @@ -32,34 +32,33 @@ trait Hanlder {
}

pub struct AdminHttpApp {
etcd: EtcdClientWrapper,
router: Router<HashMap<Method, Box<dyn Hanlder + Send + Sync>>>,

config: Admin,
etcd: EtcdClientWrapper,
router: Router<HashMap<Method, Box<dyn Handler + Send + Sync>>>,
}

impl AdminHttpApp {
pub fn new(cfg: &Pingsix) -> Self {
let mut this = Self {
config: cfg.admin.clone().unwrap(),
etcd: EtcdClientWrapper::new(cfg.etcd.clone().unwrap()),
router: Router::new(),
config: cfg.admin.clone().unwrap(),
};

this.route(
"/apisix/admin/{resource}/{id}",
Method::PUT,
Box::new(ResourcePutHanlder {}),
Box::new(ResourcePutHandler {}),
)
.route(
"/apisix/admin/{resource}/{id}",
Method::GET,
Box::new(ResourceGetHanlder {}),
Box::new(ResourceGetHandler {}),
)
.route(
"/apisix/admin/{resource}/{id}",
Method::DELETE,
Box::new(ResourceDeleteHanlder {}),
Box::new(ResourceDeleteHandler {}),
);

this
Expand All @@ -70,7 +69,7 @@ impl AdminHttpApp {
&mut self,
path: &str,
method: Method,
handler: Box<dyn Hanlder + Send + Sync>,
handler: Box<dyn Handler + Send + Sync>,
) -> &mut Self {
if self.router.at(path).is_err() {
let mut hanlders = HashMap::new();
Expand Down Expand Up @@ -142,10 +141,10 @@ struct ValueWrapper<T> {
value: T,
}

struct ResourcePutHanlder;
struct ResourcePutHandler;

#[async_trait]
impl Hanlder for ResourcePutHanlder {
impl Handler for ResourcePutHandler {
async fn handle(
&self,
etcd: &EtcdClientWrapper,
Expand Down Expand Up @@ -176,10 +175,10 @@ impl Hanlder for ResourcePutHanlder {
}
}

struct ResourceGetHanlder;
struct ResourceGetHandler;

#[async_trait]
impl Hanlder for ResourceGetHanlder {
impl Handler for ResourceGetHandler {
async fn handle(
&self,
etcd: &EtcdClientWrapper,
Expand Down Expand Up @@ -222,10 +221,10 @@ impl Hanlder for ResourceGetHanlder {
}
}

struct ResourceDeleteHanlder;
struct ResourceDeleteHandler;

#[async_trait]
impl Hanlder for ResourceDeleteHanlder {
impl Handler for ResourceDeleteHandler {
async fn handle(
&self,
etcd: &EtcdClientWrapper,
Expand Down
4 changes: 2 additions & 2 deletions src/service/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ impl ProxyHttp for HttpService {
ctx: &mut Self::CTX,
) -> Result<Box<HttpPeer>> {
let peer = ctx.route.as_ref().unwrap().select_http_peer(session);
if let Ok(ref p) = peer {
if let Ok(ref peer) = peer {
ctx.vars
.insert("upstream".to_string(), p._address.to_string());
.insert("upstream".to_string(), peer._address.to_string());
}
peer
}
Expand Down

0 comments on commit 73359d0

Please sign in to comment.