service/app/mix/controller/healthcheck.go

43 lines
777 B
Go
Raw Permalink Normal View History

2024-05-14 09:48:34 +08:00
package controller
import (
"github.com/gin-gonic/gin"
2024-05-21 17:36:33 +08:00
"net"
2024-05-14 09:48:34 +08:00
"service/bizcommon/util"
2024-05-21 17:36:33 +08:00
"strings"
2024-05-14 09:48:34 +08:00
"time"
)
func Healthcheck(ctx *gin.Context) {
data := map[string]interface{}{
"time": time.Now().Unix(),
"time_str": util.GetTodayZeroTime().Format(time.RFC3339),
}
ReplyOk(ctx, data)
}
2024-05-21 17:36:33 +08:00
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
}