Merge branch 'dev-lwl/consul' into test

This commit is contained in:
lwl0608 2024-05-21 17:36:39 +08:00
commit ce46abfdca
2 changed files with 28 additions and 0 deletions

View File

@ -2,7 +2,9 @@ package controller
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"net"
"service/bizcommon/util" "service/bizcommon/util"
"strings"
"time" "time"
) )
@ -13,3 +15,28 @@ func Healthcheck(ctx *gin.Context) {
} }
ReplyOk(ctx, data) ReplyOk(ctx, data)
} }
func TestIp(ctx *gin.Context) {
ReplyOk(ctx, getIp())
}
func getIp() string {
addrs, err := net.InterfaceAddrs()
if err != nil {
return "127.0.0.1"
}
retIp := ""
for _, address := range addrs {
// 检查ip地址判断是否回环地址
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
ip := ipnet.IP.String()
if strings.HasPrefix(ip, "172.") {
retIp = ip
break
}
}
}
}
return retIp
}

View File

@ -56,6 +56,7 @@ func Init(r *gin.Engine) {
// healthcheck // healthcheck
r.GET("/healthcheck", Healthcheck) r.GET("/healthcheck", Healthcheck)
r.GET("/test/ip", TestIp)
r.GET("/timeout", Timeout) r.GET("/timeout", Timeout)
// Hello World! // Hello World!