feat(restful): tag read api support synchronous mode

This commit is contained in:
eeff
2023-10-12 14:19:55 +08:00
parent fbc1ec4708
commit 5cb150a1ef
3 changed files with 19 additions and 9 deletions
+1
View File
@@ -108,6 +108,7 @@ void neu_json_decode_write_free(neu_json_write_t *req);
typedef struct {
char *group;
char *node;
bool sync;
} neu_json_read_req_t;
int neu_json_decode_read_req(char *buf, neu_json_read_req_t **result);
+2 -1
View File
@@ -43,7 +43,8 @@ void handle_read(nng_aio *aio)
strcpy(cmd.driver, req->node);
strcpy(cmd.group, req->group);
ret = neu_plugin_op(plugin, header, &cmd);
cmd.sync = req->sync;
ret = neu_plugin_op(plugin, header, &cmd);
if (ret != 0) {
NEU_JSON_RESPONSE_ERROR(NEU_ERR_IS_BUSY, {
neu_http_response(aio, NEU_ERR_IS_BUSY, result_error);
+16 -8
View File
@@ -413,14 +413,21 @@ int neu_json_decode_read_req(char *buf, neu_json_read_req_t **result)
json_obj = neu_json_decode_new(buf);
neu_json_elem_t req_elems[] = { {
.name = "node",
.t = NEU_JSON_STR,
},
{
.name = "group",
.t = NEU_JSON_STR,
} };
neu_json_elem_t req_elems[] = {
{
.name = "node",
.t = NEU_JSON_STR,
},
{
.name = "group",
.t = NEU_JSON_STR,
},
{
.name = "sync",
.t = NEU_JSON_BOOL,
.attribute = NEU_JSON_ATTRIBUTE_OPTIONAL,
},
};
ret = neu_json_decode_by_json(json_obj, NEU_JSON_ELEM_SIZE(req_elems),
req_elems);
if (ret != 0) {
@@ -429,6 +436,7 @@ int neu_json_decode_read_req(char *buf, neu_json_read_req_t **result)
req->node = req_elems[0].v.val_str;
req->group = req_elems[1].v.val_str;
req->sync = req_elems[2].v.val_bool;
*result = req;
goto decode_exit;