Skip to content

Commit c4cb4e1

Browse files
committed
Fixed ip key
1 parent 8c98f97 commit c4cb4e1

File tree

4 files changed

+7
-24
lines changed

4 files changed

+7
-24
lines changed

context/keys/keys.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const (
1818
RequestLogID
1919

2020
RequestIDStr = "X-Request-Id"
21+
IPAddressStr = "IP-Address"
2122
)
2223

2324
func GetAsString(ctx context.Context, key ContextKey) string {

server/middleware/ctx.go

Lines changed: 0 additions & 18 deletions
This file was deleted.

server/middleware/ip_address.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
func SetIPAddress(next echo.HandlerFunc) echo.HandlerFunc {
1111
return func(c echo.Context) error {
1212
ip := keys.GetIPAddress(c.Request().Header)
13-
c.Set(keys.IPAddress, ip)
13+
c.Set(keys.IPAddressStr, ip)
1414

15-
ctx := context.WithValue(c.Request().Context(), keys.IPAddress, ip)
15+
ctx := context.WithValue(c.Request().Context(), keys.IPAddressStr, ip)
1616
c.SetRequest(c.Request().WithContext(ctx))
1717
return next(c)
1818
}

server/middleware/logger.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ func SetLogger(next echo.HandlerFunc) echo.HandlerFunc {
1212
return func(c echo.Context) error {
1313
// get request's context
1414
ctx := c.Request().Context()
15-
ipAddress, _ := c.Get(keys.IPAddress).(string)
16-
identityID, _ := keys.GetCtxValue(ctx, keys.IdentityID).(string)
17-
requestID, _ := keys.GetCtxValue(ctx, keys.RequestID).(string)
18-
msgID, _ := keys.GetCtxValue(ctx, keys.MSGID).(string)
15+
ipAddress, _ := keys.GetAsString(ctx, keys.IPAddressStr)
16+
identityID, _ := keys.GetAsString(ctx, keys.IdentityID)
17+
requestID, _ := keys.GetAsString(ctx, keys.RequestID)
18+
msgID, _ := keys.GetAsString(ctx, keys.MSGID)
1919

2020
logInfo := logger.ServiceContext{
2121
Service: verser.GetService(),

0 commit comments

Comments
 (0)