From 40b983805d59a0561328c14cf42660bf2a865094 Mon Sep 17 00:00:00 2001 From: Notealot <714804968@qq.com> Date: Thu, 21 Oct 2021 10:17:38 +0800 Subject: [PATCH] refactor for switch --- context.go | 10 +--------- gin.go | 4 ++-- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/context.go b/context.go index b4a362889c..d12771e48a 100644 --- a/context.go +++ b/context.go @@ -743,16 +743,8 @@ func (c *Context) ClientIP() string { switch c.engine.TrustedPlatform { case "": // TrustedPlatform is empty, do nothing - case PlatformGoogleAppEngine: - if addr := c.requestHeader("X-Appengine-Remote-Addr"); addr != "" { - return addr - } - case PlatformCloudflare: - if addr := c.requestHeader("CF-Connecting-IP"); addr != "" { - return addr - } default: - // Developers can define their own header of Trusted Platform + // Developers can define their own header of Trusted Platform or use predefined constants if addr := c.requestHeader(c.engine.TrustedPlatform); addr != "" { return addr } diff --git a/gin.go b/gin.go index af83161b68..3ef9b0fef6 100644 --- a/gin.go +++ b/gin.go @@ -59,10 +59,10 @@ type RoutesInfo []RouteInfo const ( // When running on Google App Engine. Trust X-Appengine-Remote-Addr // for determining the client's IP - PlatformGoogleAppEngine = "google-app-engine" + PlatformGoogleAppEngine = "X-Appengine-Remote-Addr" // When using Cloudflare's CDN. Trust CF-Connecting-IP for determining // the client's IP - PlatformCloudflare = "cloudflare" + PlatformCloudflare = "CF-Connecting-IP" ) // Engine is the framework's instance, it contains the muxer, middleware and configuration settings.