consul.h 1.2 KB

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