中间件底层,websocket

RcfConfig.cpp 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include "RcfConfig.h"
  2. #include <yaml-cpp/yaml.h>
  3. #include <fstream>
  4. using namespace std;
  5. #pragma comment(lib,"libyaml-cppmd-mt.lib")
  6. #define YAMLCONFIGFILEPATH "RcfConfig.yml"
  7. RcfConfig::RcfConfig()
  8. {
  9. try
  10. {
  11. YAML::Node node = YAML::LoadFile(YAMLCONFIGFILEPATH);
  12. if (node["Rcf"])
  13. {
  14. this->m_RcfIp = node["Rcf"]["IP"].as<string>();
  15. this->m_RcfPort = node["Rcf"]["PORT"].as<int>();
  16. }
  17. if (node["Redis"])
  18. {
  19. this->m_RedisIp = node["Redis"]["IP"].as<string>();
  20. this->m_RedisPort = node["Redis"]["PORT"].as<int>();
  21. if (node["Redis"]["PWD"].IsNull())
  22. this->m_RedisPwd = "";
  23. else
  24. this->m_RedisPwd = node["Redis"]["PWD"].as<string>();
  25. }
  26. if (node["Http"])
  27. {
  28. this->m_HttpPort = node["Http"]["PORT"].as<int>();
  29. }
  30. if (node["Https"])
  31. {
  32. this->m_HttpsPort = node["Https"]["PORT"].as<int>();
  33. }
  34. }
  35. catch (const std::exception&)
  36. {
  37. // 配置文件 读取异常,重新初始化配置文件
  38. YAML::Node node;
  39. std::ofstream fout(YAMLCONFIGFILEPATH);
  40. node["Rcf"]["IP"] = "127.0.0.1";
  41. node["Rcf"]["PORT"] = 5001;
  42. node["Redis"]["IP"] = "127.0.0.1";
  43. node["Redis"]["PORT"] = 6379;
  44. node["Redis"]["PWD"] = "";
  45. node["Http"]["PORT"] = 8000;
  46. node["Https"]["PORT"] = 8443;
  47. fout << node;
  48. fout.close();
  49. this->m_RcfIp = node["Rcf"]["IP"].as<string>();
  50. this->m_RcfPort = node["Rcf"]["PORT"].as<int>();
  51. this->m_RedisIp = node["Redis"]["IP"].as<string>();
  52. this->m_RedisPort = node["Redis"]["PORT"].as<int>();
  53. this->m_HttpPort = node["Http"]["PORT"].as<int>();
  54. this->m_HttpsPort = node["Https"]["PORT"].as<int>();
  55. }
  56. }
  57. RcfConfig RcfConfig::instance;