ipv6-test-backend/internal/router/routes/ip/myip.go

20 lines
352 B
Go
Raw Permalink Normal View History

2024-08-17 08:31:47 +08:00
package ip
import (
"github.com/gin-gonic/gin"
2024-08-20 13:38:32 +08:00
"ipv6-test-node/internal/pkg/protocol"
2024-08-18 23:23:18 +08:00
"ipv6-test-node/internal/pkg/utils"
2024-08-20 13:38:32 +08:00
"net"
2024-08-17 08:31:47 +08:00
"net/http"
2024-08-18 23:23:18 +08:00
"strconv"
2024-08-17 08:31:47 +08:00
)
func MyIP(c *gin.Context) {
2024-08-20 13:38:32 +08:00
ip := utils.ToIP(net.ParseIP(c.ClientIP()))
c.JSON(http.StatusOK, protocol.MyIPResponse{
2024-08-18 23:23:18 +08:00
Address: c.ClientIP(),
2024-08-20 13:38:32 +08:00
Version: strconv.Itoa(int(ip.Version)),
2024-08-18 23:23:18 +08:00
})
2024-08-17 08:31:47 +08:00
}