mirror of
https://github.com/KingDuckZ/kamokan.git
synced 2024-12-27 21:35:41 +00:00
Load redis parameters from config file.
This commit is contained in:
parent
6a6d4c85bb
commit
2dd4ebe515
3 changed files with 37 additions and 3 deletions
|
@ -7,8 +7,8 @@ find_package(SourceHighlight REQUIRED)
|
|||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
set(TAWASHI_CONFIG_PATH "etc")
|
||||
set(TAWASHI_CONFIG_FILE "${PROJECT_NAME}.ini")
|
||||
set(TAWASHI_CONFIG_PATH "etc" CACHE STRING "Path where config file will be located, absolute or relative to the install prefix")
|
||||
set(TAWASHI_CONFIG_FILE "${PROJECT_NAME}.ini" CACHE STRING "Filename of the config file in TAWASHI_CONFIG_PATH")
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
main.cpp
|
||||
|
@ -24,6 +24,7 @@ add_executable(${PROJECT_NAME}
|
|||
index_response.cpp
|
||||
pastie_response.cpp
|
||||
ini_file.cpp
|
||||
pathname/pathname.cpp
|
||||
)
|
||||
|
||||
configure_file(
|
||||
|
|
33
src/main.cpp
33
src/main.cpp
|
@ -21,18 +21,49 @@
|
|||
#include "pastie_response.hpp"
|
||||
#include "index_response.hpp"
|
||||
#include "cgi_env.hpp"
|
||||
#include "ini_file.hpp"
|
||||
#include "pathname/pathname.hpp"
|
||||
#include "duckhandy/compatibility.h"
|
||||
#include "duckhandy/lexical_cast.hpp"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <ciso646>
|
||||
|
||||
//www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4150.pdf
|
||||
|
||||
namespace {
|
||||
std::string config_file_path() a_pure;
|
||||
|
||||
std::string config_file_path() {
|
||||
mchlib::PathName config_path(TAWASHI_CONFIG_PATH);
|
||||
mchlib::PathName full_path("");
|
||||
if (config_path.is_absolute()) {
|
||||
full_path = std::move(config_path);
|
||||
}
|
||||
else {
|
||||
full_path = mchlib::PathName(TAWASHI_PATH_PREFIX);
|
||||
full_path.join(config_path);
|
||||
}
|
||||
full_path.join(TAWASHI_CONFIG_FILE);
|
||||
return full_path.path();
|
||||
}
|
||||
} //unnamed namespace
|
||||
|
||||
int main() {
|
||||
//std::cout << "Content-type:text/plain\n\n";
|
||||
|
||||
redis::IncRedis incredis("127.0.0.1", 6379);
|
||||
#if !defined(NDEBUG)
|
||||
std::cerr << "Loading config: \"" << config_file_path() << "\"\n";
|
||||
#endif
|
||||
std::ifstream conf(config_file_path());
|
||||
conf >> std::noskipws;
|
||||
tawashi::IniFile ini = tawashi::IniFile(std::istream_iterator<char>(conf), std::istream_iterator<char>());
|
||||
conf.close();
|
||||
const auto& settings = ini.parsed().at("tawashi");
|
||||
|
||||
redis::IncRedis incredis(std::string(settings.at("redis_server")), dhandy::lexical_cast<uint16_t>(settings.at("redis_port")));
|
||||
incredis.connect();
|
||||
|
||||
tawashi::cgi::Env cgi_env;
|
||||
|
|
|
@ -34,6 +34,8 @@ namespace mchlib {
|
|||
explicit PathName ( boost::string_ref parPath );
|
||||
~PathName ( void ) noexcept = default;
|
||||
|
||||
PathName& operator= ( PathName&& ) = default;
|
||||
|
||||
bool is_absolute ( void ) const { return m_absolute; }
|
||||
std::string path ( void ) const;
|
||||
std::size_t str_path_size ( void ) const;
|
||||
|
|
Loading…
Reference in a new issue