-
Notifications
You must be signed in to change notification settings - Fork 29
/
main.go
49 lines (42 loc) · 1.19 KB
/
main.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
package main
import (
"encoding/json"
"fmt"
"net/http"
eureka "github.com/xuanbo/eureka-client"
)
func main() {
// create eureka client
client := eureka.NewClient(&eureka.Config{
DefaultZone: "http://localhost:8761/eureka/",
App: "go-example",
Port: 10000,
RenewalIntervalInSecs: 10,
RegistryFetchIntervalSeconds: 15,
DurationInSecs: 30,
Metadata: map[string]interface{}{
"VERSION": "0.1.0",
"NODE_GROUP_ID": 0,
"PRODUCT_CODE": "DEFAULT",
"PRODUCT_VERSION_CODE": "DEFAULT",
"PRODUCT_ENV_CODE": "DEFAULT",
"SERVICE_VERSION_CODE": "DEFAULT",
},
}, func(instance *eureka.Instance) {
// custom instance
instance.InstanceID = "go-example"
})
// start client, register、heartbeat、refresh
client.Start()
// http server
http.HandleFunc("/v1/services", func(writer http.ResponseWriter, request *http.Request) {
// full applications from eureka server
apps := client.Applications
b, _ := json.Marshal(apps)
_, _ = writer.Write(b)
})
// start http server
if err := http.ListenAndServe(":10000", nil); err != nil {
fmt.Println(err)
}
}