mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-16 21:32:11 +08:00
refactor for switch
This commit is contained in:
parent
4307d8386f
commit
40b983805d
10
context.go
10
context.go
@ -743,16 +743,8 @@ func (c *Context) ClientIP() string {
|
|||||||
switch c.engine.TrustedPlatform {
|
switch c.engine.TrustedPlatform {
|
||||||
case "":
|
case "":
|
||||||
// TrustedPlatform is empty, do nothing
|
// 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:
|
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 != "" {
|
if addr := c.requestHeader(c.engine.TrustedPlatform); addr != "" {
|
||||||
return addr
|
return addr
|
||||||
}
|
}
|
||||||
|
4
gin.go
4
gin.go
@ -59,10 +59,10 @@ type RoutesInfo []RouteInfo
|
|||||||
const (
|
const (
|
||||||
// When running on Google App Engine. Trust X-Appengine-Remote-Addr
|
// When running on Google App Engine. Trust X-Appengine-Remote-Addr
|
||||||
// for determining the client's IP
|
// 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
|
// When using Cloudflare's CDN. Trust CF-Connecting-IP for determining
|
||||||
// the client's IP
|
// the client's IP
|
||||||
PlatformCloudflare = "cloudflare"
|
PlatformCloudflare = "CF-Connecting-IP"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Engine is the framework's instance, it contains the muxer, middleware and configuration settings.
|
// Engine is the framework's instance, it contains the muxer, middleware and configuration settings.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user