mirror of
https://github.com/labstack/echo.git
synced 2025-01-26 03:20:08 +02:00
Moved code around
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
a507447135
commit
143f563734
@ -15,13 +15,12 @@ func Logger() echo.MiddlewareFunc {
|
|||||||
req := c.Request()
|
req := c.Request()
|
||||||
res := c.Response()
|
res := c.Response()
|
||||||
|
|
||||||
var remoteAddr string
|
remoteAddr := req.RemoteAddr
|
||||||
if ip := req.Header.Get(echo.XRealIP); ip != "" {
|
if ip := req.Header.Get(echo.XRealIP); ip != "" {
|
||||||
remoteAddr = ip
|
remoteAddr = ip
|
||||||
} else if ip = req.Header.Get(echo.XForwardedFor); ip != "" {
|
} else if ip = req.Header.Get(echo.XForwardedFor); ip != "" {
|
||||||
remoteAddr = ip
|
remoteAddr = ip
|
||||||
} else {
|
} else {
|
||||||
remoteAddr = req.RemoteAddr
|
|
||||||
remoteAddr, _, _ = net.SplitHostPort(remoteAddr)
|
remoteAddr, _, _ = net.SplitHostPort(remoteAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ func TestLogger(t *testing.T) {
|
|||||||
Logger()(h)(c)
|
Logger()(h)(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLogger_IPAddress(t *testing.T) {
|
func TestLoggerIPAddress(t *testing.T) {
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
log.SetOutput(buf)
|
log.SetOutput(buf)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user