gateway/main.go

48 lines
944 B
Go
Raw Normal View History

2021-08-31 09:39:38 +08:00
package main
import (
"fmt"
"github.com/gin-gonic/gin"
"net"
"net/http"
)
2021-08-31 14:14:14 +08:00
func getIps() []string {
2021-08-31 09:39:38 +08:00
addrs, err := net.InterfaceAddrs()
if err != nil {
2021-08-31 14:14:14 +08:00
return nil
2021-08-31 09:39:38 +08:00
}
2021-08-31 14:14:14 +08:00
var ips []string
2021-08-31 09:39:38 +08:00
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)
2021-08-31 14:14:14 +08:00
ips = append(ips, ip)
2021-08-31 09:39:38 +08:00
}
}
}
2021-08-31 14:14:14 +08:00
//ipStr := strings.Join(aaaa, ",")
return ips
2021-08-31 09:39:38 +08:00
}
func main() {
app := gin.Default()
initNacos()
app.GET("/hello", func(context *gin.Context) {
context.String(http.StatusOK, get("get", context.Request.RequestURI))
})
app.POST("/hello", func(context *gin.Context) {
context.String(http.StatusOK, post(context.Request.RequestURI))
})
app.GET("/ip", func(context *gin.Context) {
context.String(http.StatusOK, get("get", context.Request.RequestURI))
})
app.Run(":8889")
}