-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ctl): define initial structure for load balancer
- Loading branch information
1 parent
68ae363
commit 8b18f7d
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#![allow(dead_code)] | ||
|
||
use std::{ | ||
collections::HashMap, | ||
net::SocketAddr | ||
}; | ||
|
||
use axum::extract::Request; | ||
use proto::common::instance::InstanceId; | ||
use proto::common::service::ServiceId; | ||
|
||
struct Balancer<S> { | ||
strategy: S, | ||
addrs: HashMap<ServiceId, Vec<(InstanceId, SocketAddr)>> | ||
} | ||
|
||
trait Strategy { | ||
async fn get_server(&self, _req: &Request) -> (InstanceId, SocketAddr); | ||
} | ||
|
||
impl<S> Balancer<S> | ||
where | ||
S: Strategy | ||
{ | ||
pub async fn run() { | ||
todo!(); | ||
} | ||
|
||
async fn next_server(&self, _req: &Request) -> (InstanceId, SocketAddr) { | ||
todo!(); | ||
} | ||
|
||
pub async fn drop_instance(&self, _id: InstanceId) { | ||
todo!(); | ||
} | ||
|
||
pub async fn add_instance(&self, _id: InstanceId, _at: SocketAddr) { | ||
todo!(); | ||
} | ||
|
||
pub async fn swap_instance(_old_id: InstanceId, _new_id: InstanceId, _new_at: SocketAddr) { | ||
todo!(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters