add relay builder
							parent
							
								
									7c9238527f
								
							
						
					
					
						commit
						cfc2228491
					
				|  | @ -88,6 +88,7 @@ pub mod file { | |||
| 
 | ||||
| /// Config fields as they are used at runtime
 | ||||
| 
 | ||||
| #[derive (Default)] | ||||
| pub struct Config { | ||||
| 	pub iso: file::Isomorphic, | ||||
| 	
 | ||||
|  |  | |||
|  | @ -184,4 +184,41 @@ impl Relay { | |||
| 		.map (|(k, _)| (*k).clone ()) | ||||
| 		.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 | ||||
| 	} | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 _
						_