1
0
mirror of https://github.com/go-kratos/kratos.git synced 2026-05-22 10:15:24 +02:00

get remote ip by SplitHostPort (#673)

Co-authored-by: wuqunlin <wuqunlin@netbank.cn>
This commit is contained in:
wusphinx
2020-12-30 19:23:55 +08:00
committed by GitHub
parent a631cbddf4
commit 5a78bda7ea
+2 -1
View File
@@ -2,6 +2,7 @@ package blademaster
import (
"fmt"
"net"
"net/http"
"strconv"
"strings"
@@ -110,7 +111,7 @@ func remoteIP(req *http.Request) (remote string) {
if remote = req.Header.Get("X-Real-IP"); remote != "" {
return
}
remote = req.RemoteAddr[:strings.Index(req.RemoteAddr, ":")]
remote, _, _ = net.SplitHostPort(req.RemoteAddr)
return
}