1
0

consul.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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[64];
  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[64];
  18. int port;
  19. consul_service_s() {
  20. name[0] = '\0';
  21. strcpy(ip, "127.0.0.1");
  22. port = 0;
  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. strcpy(protocol, "TCP");
  34. url[0] = '\0';
  35. strcpy(status, "passing");
  36. interval = 10000;
  37. timeout = 3000;
  38. }
  39. } consul_health_t;
  40. int register_service(consul_node_t* node, consul_service_t* service, consul_health_t* health);
  41. int deregister_service(consul_node_t* node, consul_service_t* service);
  42. int discover_services(consul_node_t* node, const char* service_name, std::vector<consul_service_t>& services);
  43. #endif // CONSUL_H_