-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.cpp
executable file
·75 lines (75 loc) · 1.87 KB
/
test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include "Consulpp.h"
#include "ConsulService.h"
#include "Check.h"
using namespace std;
void menu() {
cout << "1.Register service" << endl;
cout << "2.delete service" << endl;
cout << "3.set value" << endl;
cout << "4.delete value" << endl;
cout << "5.get value" << endl;
cout << "6.exit" << endl;
}
void register_service(CConsulpp& ctx) {
CConsulService service;
service.SetAddress("121.121.1.186");
CCheck check;
check.SetId("client_test_check");
check.SetInterval("5s");
check.SetName("Client test check");
check.SetTcp("121.121.1.186:22");
check.SetTimeout("1s");
check.SetNote("test note");
service.SetCheck(check);
service.SetId("test_service_id");
service.SetMeta("version", "1.2.3");
service.SetMeta("test_meta", "test_meta_value");
service.SetName("client_test_servie");
service.SetPort(22);
service.SetTag("client");
service.SetTag("test");
ctx.RegisterService(service);
}
void delete_service(CConsulpp& ctx) {
ctx.Deregister("test_service_id");
}
void set_value(CConsulpp& ctx) {
ctx.SetValue("client/client_test", "test");
}
void delete_value(CConsulpp& ctx) {
ctx.DeleteValue("client/client_test");
}
void get_value(CConsulpp& ctx) {
cout << ctx.GetValue("client/client_test") << endl;;
}
int main() {
CConsulpp ctx("121.121.1.195",8500);
while (true)
{
menu();
switch (getchar())
{
case '1':
register_service(ctx);
break;
case '2':
delete_service(ctx);
break;
case '3':
set_value(ctx);
break;
case '4':
delete_value(ctx);
break;
case '5':
get_value(ctx);
break;
case '6':
exit(0);
break;
default:
break;
}
}
}