forked from Pc6/service-discovery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.go
65 lines (54 loc) · 951 Bytes
/
example.go
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
package main
import (
"fmt"
"log"
"time"
"github.com/coreos/etcd/clientv3"
)
var (
client *clientv3.Client
)
var (
dialTimeout = 5 * time.Second
requestTimeout = 2 * time.Second
delayTime = 500 * time.Millisecond
endPoints = []string{"localhost:2379"}
)
const (
prefix = "service/"
ttl = int64(5)
)
func init() {
var err error
client, err = clientv3.New(clientv3.Config{
Endpoints: endPoints,
DialTimeout: dialTimeout,
})
if err != nil {
log.Fatal(err)
}
}
func main() {
fmt.Println("before watch")
WatchServices("test")
info := &ServiceInfo{
Name: "test",
IP: "192.168.0.1",
Port: 9090,
Version: 1,
}
err := Register("test", info)
if err != nil {
fmt.Println(err)
}
time.Sleep(5 * time.Second)
info = GetServiceInfo("test")
fmt.Printf("info: %v\n", *info)
err = Deregister("test")
if err != nil {
fmt.Println(err)
}
fmt.Println("deregister service")
for {
}
}