-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathac_config.c
59 lines (51 loc) · 1.33 KB
/
ac_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
/*
* Description:
* History: yang@haipo.me, 2016/04/19, create
*/
# include "ac_config.h"
struct settings settings;
static int do_load_config(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_svr(root, "svr", &settings.svr);
if (ret < 0) {
printf("load svr config fail: %d\n", ret);
return -__LINE__;
}
ret = load_cfg_redis_sentinel(root, "redis", &settings.redis);
if (ret < 0) {
printf("load redis config fail: %d\n", ret);
return -__LINE__;
}
return 0;
}
int load_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 = do_load_config(root);
if (ret < 0) {
json_decref(root);
return -__LINE__;
}
json_decref(root);
return 0;
}