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