Skip to content

Commit 718db76

Browse files
committed
[解析配置] 将配置文件解析成结构体
1 parent 4e9cd47 commit 718db76

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

frp-config/frpc_full.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ admin_port = 7400
5454
admin_user = admin
5555
admin_pwd = admin
5656
# Admin assets directory. By default, these assets are bundled with frpc.
57-
# assets_dir = ./static
57+
assets_dir = ./static
5858

5959
# connections will be established in advance, default value is zero
6060
pool_count = 5
@@ -90,8 +90,8 @@ tls_enable = true
9090

9191
# heartbeat configure, it's not recommended to modify the default value
9292
# the default value of heartbeat_interval is 10 and heartbeat_timeout is 90
93-
# heartbeat_interval = 30
94-
# heartbeat_timeout = 90
93+
heartbeat_interval = 10
94+
heartbeat_timeout = 90
9595

9696
# additional meta info for client
9797
meta_var1 = 123

frp-config/src/client.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,35 @@ pub struct Common {
3434
login_fail_exit: bool,
3535
protocol: String,
3636
tls_enable: bool,
37-
tls_cert_file: String,
38-
tls_key_file: String,
39-
tls_trusted_ca_file: String,
40-
tls_server_name: String,
41-
dns_server: IpAddr,
42-
start: String,
37+
tls_cert_file: Option<String>,
38+
tls_key_file: Option<String>,
39+
tls_trusted_ca_file: Option<String>,
40+
tls_server_name: Option<String>,
41+
dns_server: Option<IpAddr>,
42+
start: Option<String>,
4343
heartbeat_interval: u8,
4444
heartbeat_timeout: u8,
45-
metas: Vec<String>,
45+
metas: Option<Vec<String>>,
4646
udp_packet_size: u16,
47-
include_conf_files: Vec<String>,
47+
include_conf_files: Option<Vec<String>>,
4848
}
4949

50+
#[derive(Debug, Deserialize, Serialize)]
5051
pub struct Config {
5152
common: Common,
5253
}
5354

5455

5556
impl Config {
56-
pub fn new(cnf_file: &Path) {
57+
pub fn new(cnf_file: &Path) -> Config {
5758
let def_str = include_str!("../frpc_full.ini");
5859
let mut def_cnf = config::Config::default();
5960
def_cnf
6061
.merge(config::File::from_str(def_str, config::FileFormat::Ini)).unwrap()
6162
.merge(config::File::from(cnf_file)).unwrap();
62-
dbg!(def_cnf.get::<HashMap<String, String>>("common").unwrap());
63+
64+
Config {
65+
common: def_cnf.get::<Common>("common").unwrap()
66+
}
6367
}
6468
}

frpc/src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@ fn main() {
1212
// 获取配置文件
1313
let cnf_file = matches.opt_get::<String>("c").unwrap().unwrap();
1414
let cnf = frp_config::client::Config::new(Path::new(&cnf_file));
15-
dbg!(cnf_file);
16-
dbg!(cnf)
15+
dbg!(cnf);
1716
}

0 commit comments

Comments
 (0)