fix(engine): wrong syntax/behaviour at prepareCIDR

This commit is contained in:
Javier Provecho Fernandez 2021-02-08 00:17:21 +00:00 committed by GitHub
parent 39b372f163
commit e14a43cc4c

4
gin.go
View File

@ -324,9 +324,9 @@ func (engine *Engine) Run(addr ...string) (err error) {
func (engine *Engine) prepareCIDR() ([]*net.IPNet, error) {
if engine.TrustedProxies != nil {
cidr := make([]*net.IPNet, len(engine.TrustedProxies), 0)
cidr := make([]*net.IPNet, 0, len(engine.TrustedProxies))
for _, trustedProxy := range engine.TrustedProxies {
if strings.Contains(trustedProxy, "/") {
if !strings.Contains(trustedProxy, "/") {
trustedProxy += "/32"
}
_, cidrNet, err := net.ParseCIDR(trustedProxy)