1.解析cfg文件,形成struct
2.cfg文件格式
virtual_server {
label JuXG-HTTPS
ip 123.103.91.122
port 443
lb_algo rr
lb_kind tun
protocol TCP
real_server {
label RealServer1
ip 123.103.91.115
port 443
weight 100
HTTP_GET {
check_port 80
path 'health'
http_recv 'Welcome to nginx'
connect_timeout 3
}
}
real_server {
label RealServer2
ip 123.103.91.116
port 443
weight 100
HTTP_GET {
check_port 80
path 'health'
http_recv 'Welcome to nginx'
connect_timeout 3
}
}
}
3.这个cfg文件取自lvs配置,我想获取里面的数据,想问大家有没有方法
不好意思才来
SegmentFault
,貌似看到有点晚了,顺手写了一个,权当冲冲人气了,?写了一段解析的代码,代码中所有配置项值都被解析成
字符串
,具体见代码实现代码
安装
使用方法
示例代码输出
Github代码记录