mirror of https://github.com/gin-gonic/gin.git
refactor: refactor make trust ip
This commit is contained in:
parent
162a228e7c
commit
0dd4fe5b48
5
gin.go
5
gin.go
|
@ -395,9 +395,8 @@ func (engine *Engine) prepareTrustedCIDRs() ([]*net.IPNet, error) {
|
||||||
|
|
||||||
cidr := make([]*net.IPNet, 0, len(engine.trustedProxies))
|
cidr := make([]*net.IPNet, 0, len(engine.trustedProxies))
|
||||||
for _, trustedProxy := range engine.trustedProxies {
|
for _, trustedProxy := range engine.trustedProxies {
|
||||||
if !strings.Contains(trustedProxy, "/") {
|
trustedProxy, err = utils.MakeTrustIP(trustedProxy)
|
||||||
trustedProxy, err = utils.MakeTrustIP(trustedProxy)
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cidr, err
|
return cidr, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func parseIP(ip string) (net.IP, error) {
|
func parseIP(ip string) (net.IP, error) {
|
||||||
|
@ -17,6 +18,9 @@ func parseIP(ip string) (net.IP, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeTrustIP(trustedIP string) (string, error) {
|
func MakeTrustIP(trustedIP string) (string, error) {
|
||||||
|
if strings.Contains(trustedIP, "/") {
|
||||||
|
return trustedIP, nil
|
||||||
|
}
|
||||||
ip, err := parseIP(trustedIP)
|
ip, err := parseIP(trustedIP)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue