middleware

package
v0.13.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRealIP added in v0.13.3

func GetRealIP(c *gin.Context, useCDN bool) (realIP string)

GetRealIP 获取真实客户端IP地址 当useCDN为true时,优先从代理头信息中获取IP;为false时,直接使用gin的ClientIP方法 参数:

  • c: gin上下文
  • useCDN: 是否使用CDN或代理,true表示使用,false表示不使用

返回值:

  • realIP: 真实客户端IP地址

func GetRealIPWithFilter added in v0.13.5

func GetRealIPWithFilter(c *gin.Context, useCDN bool, whitelist, blacklist []string) (realIP string)

GetRealIPWithFilter 获取真实客户端IP地址(带过滤功能) 参数:

  • c: gin上下文
  • useCDN: 是否使用CDN或代理,true表示使用,false表示不使用
  • whitelist: IP白名单列表,如果提供则只允许白名单内的IP
  • blacklist: IP黑名单列表,如果提供则拒绝黑名单内的IP

返回值:

  • realIP: 真实客户端IP地址

Types

type Base

type Base struct {
}

func (Base) Cors

func (b Base) Cors() gin.HandlerFunc

Cors 开放所有接口的OPTIONS方法

func (Base) SetGPC

func (b Base) SetGPC(e *gin.Engine) gin.HandlerFunc

SetGPC 设置响应头

func (Base) SetRealIP added in v0.13.3

func (b Base) SetRealIP(useCDN bool) gin.HandlerFunc

SetRealIP 设置真实IP到gin上下文

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL