Skip to content

Commit

Permalink
feat(ctl): define initial structure for load balancer
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavodiasag committed Jun 19, 2024
1 parent 68ae363 commit 8b18f7d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
44 changes: 44 additions & 0 deletions ctl/src/balancer/mod.rs
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!();
}
}
1 change: 1 addition & 0 deletions ctl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{discovery::Discovery, http::HttpState};

mod discovery;
mod http;
mod balancer;

#[tokio::main]
async fn main() {
Expand Down

0 comments on commit 8b18f7d

Please sign in to comment.