49 lines
955 B
Go
49 lines
955 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/gin-gonic/gin"
|
|
"net"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
func getIps() string {
|
|
addrs, err := net.InterfaceAddrs()
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
var aaaa []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)
|
|
}
|
|
}
|
|
}
|
|
ipStr := strings.Join(aaaa, ",")
|
|
return ipStr
|
|
}
|
|
|
|
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")
|
|
}
|