mirror of
https://gitee.com/an-tao/drogon.git
synced 2024-11-30 10:47:40 +08:00
Add ConfigLoader::ConfigLoader(const Json::Value &data) (#579)
This commit is contained in:
parent
c320527f9d
commit
6fca7067da
@ -340,6 +340,23 @@ class HttpAppFramework : public trantor::NonCopyable
|
||||
*/
|
||||
virtual HttpAppFramework &loadConfigFile(const std::string &fileName) = 0;
|
||||
|
||||
/// Load the configuration from a Json::Value Object.
|
||||
/**
|
||||
* @param Json::Value Object containing the configuration.
|
||||
* @note Please refer to the configuration file for the content of the json
|
||||
* object.
|
||||
*/
|
||||
virtual HttpAppFramework &loadConfigJson(const Json::Value &data) = 0;
|
||||
|
||||
/// Load the configuration from a Json::Value Object.
|
||||
/**
|
||||
* @param rvalue reference to a Json::Value object containing the
|
||||
* configuration.
|
||||
* @note Please refer to the configuration file for the content of the json
|
||||
* object.
|
||||
*/
|
||||
virtual HttpAppFramework &loadConfigJson(Json::Value &&data) = 0;
|
||||
|
||||
/// Register a HttpSimpleController object into the framework.
|
||||
/**
|
||||
* @param pathName When the path of a http request is equal to the
|
||||
|
@ -130,6 +130,13 @@ ConfigLoader::ConfigLoader(const std::string &configFile)
|
||||
}
|
||||
}
|
||||
}
|
||||
ConfigLoader::ConfigLoader(const Json::Value &data) : configJsonRoot_(data)
|
||||
{
|
||||
}
|
||||
ConfigLoader::ConfigLoader(Json::Value &&data)
|
||||
: configJsonRoot_(std::move(data))
|
||||
{
|
||||
}
|
||||
ConfigLoader::~ConfigLoader()
|
||||
{
|
||||
}
|
||||
|
@ -24,6 +24,8 @@ class ConfigLoader : public trantor::NonCopyable
|
||||
{
|
||||
public:
|
||||
explicit ConfigLoader(const std::string &configFile);
|
||||
explicit ConfigLoader(const Json::Value &data);
|
||||
explicit ConfigLoader(Json::Value &&data);
|
||||
~ConfigLoader();
|
||||
const Json::Value &jsonValue() const
|
||||
{
|
||||
|
@ -333,6 +333,20 @@ HttpAppFramework &HttpAppFrameworkImpl::loadConfigFile(
|
||||
jsonConfig_ = loader.jsonValue();
|
||||
return *this;
|
||||
}
|
||||
HttpAppFramework &HttpAppFrameworkImpl::loadConfigJson(const Json::Value &data)
|
||||
{
|
||||
ConfigLoader loader(data);
|
||||
loader.load();
|
||||
jsonConfig_ = loader.jsonValue();
|
||||
return *this;
|
||||
}
|
||||
HttpAppFramework &HttpAppFrameworkImpl::loadConfigJson(Json::Value &&data)
|
||||
{
|
||||
ConfigLoader loader(std::move(data));
|
||||
loader.load();
|
||||
jsonConfig_ = loader.jsonValue();
|
||||
return *this;
|
||||
}
|
||||
HttpAppFramework &HttpAppFrameworkImpl::setLogPath(
|
||||
const std::string &logPath,
|
||||
const std::string &logfileBaseName,
|
||||
@ -999,4 +1013,4 @@ const std::function<HttpResponsePtr(HttpStatusCode)>
|
||||
std::vector<trantor::InetAddress> HttpAppFrameworkImpl::getListeners() const
|
||||
{
|
||||
return listenerManagerPtr_->getListeners();
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "impl_forwards.h"
|
||||
#include <drogon/HttpAppFramework.h>
|
||||
#include <drogon/config.h>
|
||||
#include <json/json.h>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <regex>
|
||||
@ -248,6 +249,8 @@ class HttpAppFrameworkImpl : public HttpAppFramework
|
||||
size_t maxConnectionsPerIP) override;
|
||||
virtual HttpAppFramework &loadConfigFile(
|
||||
const std::string &fileName) override;
|
||||
virtual HttpAppFramework &loadConfigJson(const Json::Value &data) override;
|
||||
virtual HttpAppFramework &loadConfigJson(Json::Value &&data) override;
|
||||
virtual HttpAppFramework &enableRunAsDaemon() override
|
||||
{
|
||||
runAsDaemon_ = true;
|
||||
|
Loading…
Reference in New Issue
Block a user