add relay builder

main
_ 2021-04-27 14:55:08 -05:00
parent 7c9238527f
commit cfc2228491
2 changed files with 38 additions and 0 deletions

View File

@ -88,6 +88,7 @@ pub mod file {
/// Config fields as they are used at runtime /// Config fields as they are used at runtime
#[derive (Default)]
pub struct Config { pub struct Config {
pub iso: file::Isomorphic, pub iso: file::Isomorphic,

View File

@ -184,4 +184,41 @@ impl Relay {
.map (|(k, _)| (*k).clone ()) .map (|(k, _)| (*k).clone ())
.collect () .collect ()
} }
pub fn build () -> Builder {
Builder::default ()
}
}
#[derive (Default)]
pub struct Builder {
config: Config,
}
impl Builder {
pub fn build (self) -> Result <Relay, RelayError> {
Relay::try_from (self.config)
}
pub fn enable_scraper_api (&mut self, b: bool) -> &mut Self {
self.config.iso.enable_scraper_api = b;
self
}
pub fn port (&mut self, port: u16) -> &mut Self {
self.config.port = Some (port);
self
}
pub fn scraper_key (&mut self, key: crate::key_validity::ScraperKey <crate::key_validity::Valid30Days>)
-> &mut Self
{
self.config.scraper_keys.insert (key.hash.encode_base64 (), key);
self
}
pub fn server (&mut self, server: crate::config::file::Server) -> &mut Self {
self.config.servers.insert (server.name.clone (), server);
self
}
} }