consul.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef CONSUL_H_
  2. #define CONSUL_H_
  3. #include <vector>
  4. #include <string.h>
  5. #include "hexport.h"
  6. typedef struct consul_node_s {
  7. // node
  8. char ip[64];
  9. int port;
  10. consul_node_s() {
  11. strcpy(ip, "127.0.0.1");
  12. port = 8500;
  13. }
  14. } consul_node_t;
  15. typedef struct consul_service_s {
  16. // service
  17. char name[64];
  18. char ip[64];
  19. int port;
  20. consul_service_s() {
  21. name[0] = '\0';
  22. strcpy(ip, "127.0.0.1");
  23. port = 0;
  24. }
  25. } consul_service_t;
  26. typedef struct consul_health_s {
  27. // check
  28. char protocol[32]; // TCP,HTTP
  29. char url[256];
  30. char status[32]; // any,passing,warning,critical
  31. int interval; // ms
  32. int timeout; // ms
  33. consul_health_s() {
  34. strcpy(protocol, "TCP");
  35. url[0] = '\0';
  36. strcpy(status, "passing");
  37. interval = 10000;
  38. timeout = 3000;
  39. }
  40. } consul_health_t;
  41. HV_EXPORT int register_service(consul_node_t* node, consul_service_t* service, consul_health_t* health);
  42. HV_EXPORT int deregister_service(consul_node_t* node, consul_service_t* service);
  43. HV_EXPORT int discover_services(consul_node_t* node, const char* service_name, std::vector<consul_service_t>& services);
  44. #endif // CONSUL_H_