config_full.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #ifndef _RPC_CONFIG_H_
  2. #define _RPC_CONFIG_H_
  3. #include <string>
  4. #include <vector>
  5. #include <unordered_map>
  6. #include "Json.h"
  7. #include "srpc/rpc_types.h"
  8. #include "srpc/rpc_define.h"
  9. #include "srpc/rpc_filter.h"
  10. namespace srpc
  11. {
  12. class RPCConfig
  13. {
  14. public:
  15. using ErrorPageMap = std::unordered_map<int, std::string>;
  16. bool load(const char *file);
  17. void load_filter(SRPCServer& server);
  18. void load_filter(SRPCClient& client);
  19. void load_filter(SRPCHttpServer& server);
  20. void load_filter(SRPCHttpClient& client);
  21. void load_filter(BRPCServer& server);
  22. void load_filter(BRPCClient& client);
  23. void load_filter(ThriftServer& server);
  24. void load_filter(ThriftClient& client);
  25. void load_filter(ThriftHttpServer& server);
  26. void load_filter(ThriftHttpClient& client);
  27. void load_filter(TRPCServer& server);
  28. void load_filter(TRPCClient& client);
  29. void load_filter(TRPCHttpServer& server);
  30. void load_filter(TRPCHttpClient& client);
  31. unsigned short server_port() const { return this->s_port; }
  32. const char *server_cert_file() const { return this->s_cert_file.c_str(); }
  33. const char *server_file_key() const { return this->s_file_key.c_str(); }
  34. unsigned short client_port() const { return this->c_port; }
  35. const char *client_host() const { return this->c_host.c_str(); }
  36. bool client_is_ssl() const { return this->c_is_ssl; }
  37. const char *client_url() const { return this->c_url.c_str(); }
  38. int redirect_max() const { return this->c_redirect_max; }
  39. int retry_max() const { return this->c_retry_max; }
  40. const char *client_caller() const { return this->c_caller.c_str(); }
  41. const char *client_user_name() const { return this->c_user_name.c_str(); }
  42. const char *client_password() const { return this->c_password.c_str(); }
  43. const char *get_root_path() const { return this->root_path.c_str(); }
  44. const ErrorPageMap& get_error_page() const { return this->error_page; }
  45. public:
  46. RPCConfig() :
  47. s_port(0), c_port(0), c_is_ssl(false), c_redirect_max(0), c_retry_max(0)
  48. { }
  49. ~RPCConfig();
  50. private:
  51. void load_server();
  52. void load_client();
  53. void load_metrics();
  54. void load_trace();
  55. wfrest::Json data;
  56. std::vector<RPCFilter *> filters;
  57. unsigned short s_port;
  58. std::string s_cert_file;
  59. std::string s_file_key;
  60. std::string c_host;
  61. unsigned short c_port;
  62. bool c_is_ssl;
  63. std::string c_url;
  64. int c_redirect_max;
  65. int c_retry_max;
  66. std::string c_caller;
  67. std::string c_user_name;
  68. std::string c_password;
  69. std::string root_path;
  70. ErrorPageMap error_page;
  71. };
  72. }
  73. #endif