This commit is contained in:
parent
ff5f07cf30
commit
7b4df0826f
23
main.go
23
main.go
@ -12,6 +12,7 @@ import (
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var port = "8888"
|
||||
@ -47,7 +48,7 @@ func initNacos() {
|
||||
ip = ips[0]
|
||||
}
|
||||
|
||||
success, err := client.RegisterInstance(vo.RegisterInstanceParam{
|
||||
regParam := vo.RegisterInstanceParam{
|
||||
Ip: ip,
|
||||
Port: pp,
|
||||
Weight: 10,
|
||||
@ -55,11 +56,27 @@ func initNacos() {
|
||||
Healthy: true,
|
||||
ServiceName: "api1",
|
||||
Ephemeral: true,
|
||||
})
|
||||
}
|
||||
success, err := client.RegisterInstance(regParam)
|
||||
log.Println("Nacos注册结果: ", success)
|
||||
if err != nil {
|
||||
log.Println("Nacos注册错误信息: ", err.Error())
|
||||
}
|
||||
if !success {
|
||||
retry := 0
|
||||
for true {
|
||||
time.Sleep(5 * time.Second)
|
||||
retry += 1
|
||||
success, err = client.RegisterInstance(regParam)
|
||||
log.Printf("Nacos第%v次注册结果: %v\n", retry, success)
|
||||
if err != nil {
|
||||
log.Println("Nacos注册错误信息: ", err.Error())
|
||||
}
|
||||
if success || retry == 10 {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
configClient, err := clients.NewConfigClient(configParam)
|
||||
if err != nil {
|
||||
@ -86,7 +103,7 @@ func getIps() []string {
|
||||
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
|
||||
if ipnet.IP.To4() != nil {
|
||||
ip := ipnet.IP.String()
|
||||
fmt.Println(ip)
|
||||
//fmt.Println(ip)
|
||||
ips = append(ips, ip)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user