Skip to content

Commit

Permalink
refactor: refactor make trust ip
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamadrezamomeni committed Jan 1, 2024
1 parent 162a228 commit 0dd4fe5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 2 additions & 3 deletions gin.go
Expand Up @@ -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)
}
trustedProxy, err = utils.MakeTrustIP(trustedProxy)

if err != nil {
return cidr, err
}
Expand Down
4 changes: 4 additions & 0 deletions utils/ip.go
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"net"
"strings"
)

func parseIP(ip string) (net.IP, error) {
Expand All @@ -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 {
Expand Down

0 comments on commit 0dd4fe5

Please sign in to comment.