1
0

consul.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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[32];
  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[32];
  19. int port;
  20. consul_service_s() {
  21. memset(this, 0, sizeof(consul_service_s));
  22. strcpy(ip, "127.0.0.1");
  23. }
  24. } consul_service_t;
  25. typedef struct consul_health_s {
  26. // check
  27. char protocol[32]; // TCP,HTTP
  28. char url[256];
  29. char status[32]; // any,passing,warning,critical
  30. int interval; // ms
  31. int timeout; // ms
  32. consul_health_s() {
  33. memset(this, 0, sizeof(consul_health_s));
  34. strcpy(protocol, "TCP");
  35. strcpy(status, "passing");
  36. interval = 10000;
  37. timeout = 3000;
  38. }
  39. } consul_health_t;
  40. HV_EXPORT int register_service(consul_node_t* node, consul_service_t* service, consul_health_t* health);
  41. HV_EXPORT int deregister_service(consul_node_t* node, consul_service_t* service);
  42. HV_EXPORT int discover_services(consul_node_t* node, const char* service_name, std::vector<consul_service_t>& services);
  43. #endif // CONSUL_H_