thehrz 145bb045e9
Some checks failed
CI / deploy (push) Failing after 2m53s
fork from xmdhs/authlib-skin
2025-01-24 16:57:58 +08:00

20 lines
297 B
Go

package utils
import (
"fmt"
"net"
"net/http"
)
func GetIP(r *http.Request) (string, error) {
ip, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
ip = r.RemoteAddr
}
netIP := net.ParseIP(ip)
if netIP != nil {
return ip, nil
}
return "", fmt.Errorf("no valid ip found")
}