Skip to content

Commit

Permalink
fix potential panic due to nil interface conversion (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErenDursun authored Aug 28, 2023
1 parent afd2ac6 commit cb9170e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func NewWithConfig(logger *slog.Logger, config Config) echo.MiddlewareFunc {
slog.String("user-agent", userAgent),
}

xForwardedFor := c.Get(echo.HeaderXForwardedFor).(string)
if len(xForwardedFor) > 0 {
xForwardedFor, ok := c.Get(echo.HeaderXForwardedFor).(string)
if ok && len(xForwardedFor) > 0 {
ips := lo.Map(strings.Split(xForwardedFor, ","), func(ip string, _ int) string {
return strings.TrimSpace(ip)
})
Expand Down

0 comments on commit cb9170e

Please sign in to comment.