mirror of
https://github.com/emqx/neuron.git
synced 2026-10-18 13:41:22 +08:00
refactor(restful): expose some utilities for monitor plugin
This commit is contained in:
@@ -52,8 +52,6 @@ struct neu_rest_handler web_handlers[] = {
|
||||
},
|
||||
};
|
||||
|
||||
static void cors(nng_aio *aio);
|
||||
|
||||
struct neu_rest_handler cors_handler[] = {
|
||||
{
|
||||
.url = "/api/v2/ping",
|
||||
@@ -338,7 +336,7 @@ void neu_rest_api_cors_handler(const struct neu_rest_handler **handlers,
|
||||
for (uint32_t i = 0; i < *size; i++) {
|
||||
cors_handler[i].method = NEU_REST_METHOD_OPTIONS;
|
||||
cors_handler[i].type = NEU_REST_HANDLER_FUNCTION;
|
||||
cors_handler[i].value.handler = cors;
|
||||
cors_handler[i].value.handler = neu_rest_handle_cors;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -360,7 +358,7 @@ void *neu_rest_get_plugin()
|
||||
return rest_ctx->plugin;
|
||||
}
|
||||
|
||||
static void cors(nng_aio *aio)
|
||||
void neu_rest_handle_cors(nng_aio *aio)
|
||||
{
|
||||
nng_http_res *res = NULL;
|
||||
|
||||
|
||||
@@ -22,6 +22,9 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <nng/nng.h>
|
||||
#include <nng/supplemental/http/http.h>
|
||||
|
||||
#include "plugin.h"
|
||||
#include "utils/neu_jwt.h"
|
||||
#include "json/neu_json_error.h"
|
||||
@@ -106,10 +109,13 @@ neu_rest_handle_ctx_t *neu_rest_init_ctx(void *plugin);
|
||||
void neu_rest_free_ctx(neu_rest_handle_ctx_t *ctx);
|
||||
void * neu_rest_get_plugin();
|
||||
|
||||
int neu_rest_add_handler(nng_http_server * server,
|
||||
const struct neu_rest_handler *rest_handler);
|
||||
void neu_rest_web_handler(const struct neu_rest_handler **handlers,
|
||||
uint32_t * size);
|
||||
void neu_rest_api_handler(const struct neu_rest_handler **handlers,
|
||||
uint32_t * size);
|
||||
void neu_rest_api_cors_handler(const struct neu_rest_handler **handlers,
|
||||
uint32_t * size);
|
||||
void neu_rest_handle_cors(nng_aio *aio);
|
||||
#endif
|
||||
|
||||
@@ -49,8 +49,8 @@ struct neu_plugin {
|
||||
neu_rest_handle_ctx_t *handle_ctx;
|
||||
};
|
||||
|
||||
static int rest_add_handler(nng_http_server * server,
|
||||
const struct neu_rest_handler *rest_handler)
|
||||
int neu_rest_add_handler(nng_http_server * server,
|
||||
const struct neu_rest_handler *rest_handler)
|
||||
{
|
||||
nng_http_handler *handler;
|
||||
int ret = -1;
|
||||
@@ -166,11 +166,11 @@ static neu_plugin_t *dashb_plugin_open(void)
|
||||
|
||||
neu_rest_api_handler(&rest_handlers, &n_handler);
|
||||
for (uint32_t i = 0; i < n_handler; i++) {
|
||||
rest_add_handler(plugin->api_server, &rest_handlers[i]);
|
||||
neu_rest_add_handler(plugin->api_server, &rest_handlers[i]);
|
||||
}
|
||||
neu_rest_api_cors_handler(&cors, &n_handler);
|
||||
for (uint32_t i = 0; i < n_handler; i++) {
|
||||
rest_add_handler(plugin->api_server, &cors[i]);
|
||||
neu_rest_add_handler(plugin->api_server, &cors[i]);
|
||||
}
|
||||
if ((rv = nng_http_server_start(plugin->api_server)) != 0) {
|
||||
nlog_error("Failed to start api server, error=%d", rv);
|
||||
@@ -179,7 +179,7 @@ static neu_plugin_t *dashb_plugin_open(void)
|
||||
|
||||
neu_rest_web_handler(&rest_handlers, &n_handler);
|
||||
for (uint32_t i = 0; i < n_handler; i++) {
|
||||
rest_add_handler(plugin->web_server, &rest_handlers[i]);
|
||||
neu_rest_add_handler(plugin->web_server, &rest_handlers[i]);
|
||||
}
|
||||
|
||||
if ((rv = nng_http_server_start(plugin->web_server)) != 0) {
|
||||
|
||||
Reference in New Issue
Block a user