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