1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3
4#[derive(Serialize, Deserialize, Clone, Debug)]
5pub struct NuttConfig {
6 project: ProjectConfig,
7 service: HashMap<String, ServiceConfig>,
8}
9
10impl NuttConfig {
11 pub fn new(name: &str, version: &str) -> Self {
12 Self {
13 project: ProjectConfig::new(name, version),
14 service: HashMap::new(),
15 }
16 }
17
18 pub fn get_service_config(&self, name: &str) -> Option<ServiceConfig> {
19 if let Some(conf) = self.service.get(name) {
20 return Some(conf.clone());
21 }
22 None
23 }
24
25 pub fn push_service_config(&mut self,name: &str, service_config: ServiceConfig) {
26 self.service.insert(name.to_string(), service_config);
27 }
28}
29
30#[derive(Serialize, Deserialize, Clone, Debug)]
31pub struct ServiceConfig {
32 local_host: String,
33 local_port: u16,
34}
35
36impl ServiceConfig {
37 pub fn new(local_host: &str, local_port: u16) -> Self {
38 Self {
39 local_host: local_host.to_string(),
40 local_port,
41 }
42 }
43
44 pub fn get_addr(&self) -> (&str, u16) {
45 (&self.local_host, self.local_port)
46 }
47}
48
49#[derive(Serialize, Deserialize, Clone, Debug)]
50pub struct ProjectConfig {
51 name: String,
52 version: String
53}
54
55impl ProjectConfig {
56 pub fn new(name: &str, version: &str) -> Self {
57 Self {
58 name: name.to_string(),
59 version: version.to_string()
60 }
61 }
62}