-
Notifications
You must be signed in to change notification settings - Fork 1
/
ah_config.c
81 lines (73 loc) · 2.19 KB
/
ah_config.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* Description:
* History: [email protected], 2017/04/21, create
*/
# include "ah_config.h"
struct settings settings;
static int read_config_from_json(json_t *root)
{
int ret;
ret = load_cfg_process(root, "process", &settings.process);
if (ret < 0) {
printf("load process config fail: %d\n", ret);
return -__LINE__;
}
ret = load_cfg_log(root, "log", &settings.log);
if (ret < 0) {
printf("load log config fail: %d\n", ret);
return -__LINE__;
}
ret = load_cfg_alert(root, "alert", &settings.alert);
if (ret < 0) {
printf("load alert config fail: %d\n", ret);
return -__LINE__;
}
ret = load_cfg_http_svr(root, "svr", &settings.svr);
if (ret < 0) {
printf("load svr config fail: %d\n", ret);
return -__LINE__;
}
ret = load_cfg_svr(root, "monitor", &settings.monitor);
if (ret < 0) {
printf("load monitor config fail: %d\n", ret);
return -__LINE__;
}
ret = load_cfg_rpc_clt(root, "matchengine", &settings.matchengine);
if (ret < 0) {
printf("load matchengine clt config fail: %d\n", ret);
return -__LINE__;
}
ret = load_cfg_rpc_clt(root, "marketprice", &settings.marketprice);
if (ret < 0) {
printf("load marketprice clt config fail: %d\n", ret);
return -__LINE__;
}
ret = load_cfg_rpc_clt(root, "readhistory", &settings.readhistory);
if (ret < 0) {
printf("load readhistory clt config fail: %d\n", ret);
return -__LINE__;
}
ERR_RET(read_cfg_real(root, "timeout", &settings.timeout, false, 1.0));
ERR_RET(read_cfg_int(root, "worker_num", &settings.worker_num, false, 1));
return 0;
}
int init_config(const char *path)
{
json_error_t error;
json_t *root = json_load_file(path, 0, &error);
if (root == NULL) {
printf("json_load_file from: %s fail: %s in line: %d\n", path, error.text, error.line);
return -__LINE__;
}
if (!json_is_object(root)) {
json_decref(root);
return -__LINE__;
}
int ret = read_config_from_json(root);
if (ret < 0) {
json_decref(root);
return ret;
}
json_decref(root);
return 0;
}