This commit is contained in:
parent
33132b3564
commit
2c81e99f4e
12
feign.go
12
feign.go
@ -37,13 +37,23 @@ func initNacos() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
ip := "gateway-demo"
|
||||||
|
if ips := getIps(); ips != nil {
|
||||||
|
ip = ips[0]
|
||||||
|
}
|
||||||
success, _ := client.RegisterInstance(vo.RegisterInstanceParam{
|
success, _ := client.RegisterInstance(vo.RegisterInstanceParam{
|
||||||
//Ip: "172.30.0.90",
|
Ip: ip,
|
||||||
Port: 8889,
|
Port: 8889,
|
||||||
Weight: 10,
|
Weight: 10,
|
||||||
|
Enable: true,
|
||||||
|
Healthy: true,
|
||||||
ServiceName: "gateway",
|
ServiceName: "gateway",
|
||||||
|
Ephemeral: true,
|
||||||
})
|
})
|
||||||
log.Println("Nacos注册结果: ", success)
|
log.Println("Nacos注册结果: ", success)
|
||||||
|
if !success {
|
||||||
|
log.Fatal("服务注册失败,退出程序")
|
||||||
|
}
|
||||||
nameClient = client
|
nameClient = client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
13
main.go
13
main.go
@ -5,27 +5,26 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func getIps() string {
|
func getIps() []string {
|
||||||
addrs, err := net.InterfaceAddrs()
|
addrs, err := net.InterfaceAddrs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return nil
|
||||||
}
|
}
|
||||||
var aaaa []string
|
var ips []string
|
||||||
for _, address := range addrs {
|
for _, address := range addrs {
|
||||||
// 检查ip地址判断是否回环地址
|
// 检查ip地址判断是否回环地址
|
||||||
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)
|
||||||
aaaa = append(aaaa, ip)
|
ips = append(ips, ip)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ipStr := strings.Join(aaaa, ",")
|
//ipStr := strings.Join(aaaa, ",")
|
||||||
return ipStr
|
return ips
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
Loading…
Reference in New Issue
Block a user