refactor: refactor make trust ip

This commit is contained in:
mohamadreza 2024-01-01 15:04:25 +03:30
parent 162a228e7c
commit 0dd4fe5b48
2 changed files with 6 additions and 3 deletions

3
gin.go
View File

@ -395,9 +395,8 @@ func (engine *Engine) prepareTrustedCIDRs() ([]*net.IPNet, error) {
cidr := make([]*net.IPNet, 0, len(engine.trustedProxies))
for _, trustedProxy := range engine.trustedProxies {
if !strings.Contains(trustedProxy, "/") {
trustedProxy, err = utils.MakeTrustIP(trustedProxy)
}
if err != nil {
return cidr, err
}

View File

@ -2,6 +2,7 @@ package utils
import (
"net"
"strings"
)
func parseIP(ip string) (net.IP, error) {
@ -17,6 +18,9 @@ func parseIP(ip string) (net.IP, error) {
}
func MakeTrustIP(trustedIP string) (string, error) {
if strings.Contains(trustedIP, "/") {
return trustedIP, nil
}
ip, err := parseIP(trustedIP)
if err != nil {