-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move router from server to a dependent crate.
- Loading branch information
Showing
18 changed files
with
126 additions
and
264 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
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,24 @@ | ||
[package] | ||
name = "router" | ||
|
||
[package.version] | ||
workspace = true | ||
|
||
[package.authors] | ||
workspace = true | ||
|
||
[package.edition] | ||
workspace = true | ||
|
||
[dependencies] | ||
async-trait = { workspace = true } | ||
ceresdbproto = { workspace = true } | ||
cluster = { workspace = true } | ||
common_types = { workspace = true } | ||
common_util = { workspace = true } | ||
log = { workspace = true } | ||
meta_client = { workspace = true } | ||
serde = { workspace = true } | ||
serde_derive = { workspace = true } | ||
snafu = { workspace = true } | ||
twox-hash = "1.6" |
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
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,67 @@ | ||
// Copyright 2022 CeresDB Project Authors. Licensed under Apache-2.0. | ||
|
||
//! Endpoint definition | ||
use std::str::FromStr; | ||
|
||
use ceresdbproto::storage; | ||
use serde_derive::Deserialize; | ||
|
||
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)] | ||
pub struct Endpoint { | ||
pub addr: String, | ||
pub port: u16, | ||
} | ||
|
||
impl Endpoint { | ||
pub fn new(addr: String, port: u16) -> Self { | ||
Self { addr, port } | ||
} | ||
} | ||
|
||
impl ToString for Endpoint { | ||
fn to_string(&self) -> String { | ||
format!("{}:{}", self.addr, self.port) | ||
} | ||
} | ||
|
||
impl FromStr for Endpoint { | ||
type Err = Box<dyn std::error::Error + Send + Sync>; | ||
|
||
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> { | ||
let (addr, raw_port) = match s.rsplit_once(':') { | ||
Some(v) => v, | ||
None => { | ||
let err_msg = "Can't find ':' in the source string".to_string(); | ||
return Err(Self::Err::from(err_msg)); | ||
} | ||
}; | ||
let port = raw_port.parse().map_err(|e| { | ||
let err_msg = format!("Fail to parse port:{}, err:{}", raw_port, e); | ||
Self::Err::from(err_msg) | ||
})?; | ||
|
||
Ok(Endpoint { | ||
addr: addr.to_string(), | ||
port, | ||
}) | ||
} | ||
} | ||
|
||
impl From<Endpoint> for storage::Endpoint { | ||
fn from(endpoint: Endpoint) -> Self { | ||
storage::Endpoint { | ||
ip: endpoint.addr, | ||
port: endpoint.port as u32, | ||
} | ||
} | ||
} | ||
|
||
impl From<storage::Endpoint> for Endpoint { | ||
fn from(endpoint_pb: storage::Endpoint) -> Self { | ||
Endpoint { | ||
addr: endpoint_pb.ip, | ||
port: endpoint_pb.port as u16, | ||
} | ||
} | ||
} |
File renamed without changes.
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
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
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.