mirror of
https://github.com/emqx/neuron.git
synced 2026-10-17 04:40:42 +08:00
feat(restful): add get version api
This commit is contained in:
@@ -124,6 +124,7 @@ set(NEURON_SOURCES
|
||||
plugins/restful/datatag_handle.c
|
||||
plugins/restful/group_config_handle.c
|
||||
plugins/restful/plugin_handle.c
|
||||
plugins/restful/version_handle.c
|
||||
plugins/restful/rest.c
|
||||
plugins/restful/http.c
|
||||
plugins/dummy/dummy.c
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "normal_handle.h"
|
||||
#include "plugin_handle.h"
|
||||
#include "rw_handle.h"
|
||||
#include "version_handle.h"
|
||||
|
||||
#include "handle.h"
|
||||
|
||||
@@ -105,6 +106,9 @@ struct neu_rest_handler cors_handler[] = {
|
||||
{
|
||||
.url = "/api/v2/license",
|
||||
},
|
||||
{
|
||||
.url = "/api/v2/version",
|
||||
},
|
||||
};
|
||||
|
||||
struct neu_rest_handler api_handlers[] = {
|
||||
@@ -284,6 +288,12 @@ struct neu_rest_handler api_handlers[] = {
|
||||
.url = "/api/v2/license",
|
||||
.value.handler = handle_get_license,
|
||||
},
|
||||
{
|
||||
.method = NEU_REST_METHOD_GET,
|
||||
.type = NEU_REST_HANDLER_FUNCTION,
|
||||
.url = "/api/v2/version",
|
||||
.value.handler = handle_get_version,
|
||||
},
|
||||
};
|
||||
|
||||
void neu_rest_web_handler(const struct neu_rest_handler **handlers,
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* NEURON IIoT System for Industry 4.0
|
||||
* Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**/
|
||||
|
||||
#include "neuron/version.h"
|
||||
#include "utils/log.h"
|
||||
#include "json/neu_json_error.h"
|
||||
#include "json/neu_json_fn.h"
|
||||
|
||||
#include "handle.h"
|
||||
#include "http.h"
|
||||
|
||||
void handle_get_version(nng_aio *aio)
|
||||
{
|
||||
char result[128] = { 0 };
|
||||
|
||||
VALIDATE_JWT(aio);
|
||||
|
||||
int ret = snprintf(
|
||||
result, sizeof(result),
|
||||
"{\"version\":\"%s\", \"revision\":\"%s\", \"build_date\":\"%s\"}",
|
||||
NEURON_VERSION, NEURON_GIT_REV NEURON_GIT_DIFF, NEURON_BUILD_DATE);
|
||||
|
||||
if ((size_t) ret >= sizeof(result)) {
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_EINTERNAL, {
|
||||
http_response(aio, error_code.error, result_error);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
http_response(aio, 0, result);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* NEURON IIoT System for Industry 4.0
|
||||
* Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**/
|
||||
|
||||
#ifndef _NEU_VERSION_HANDLE_H_
|
||||
#define _NEU_VERSION_HANDLE_H_
|
||||
|
||||
#include <nng/nng.h>
|
||||
|
||||
void handle_get_version(nng_aio *aio);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user