mirror of https://github.com/gin-gonic/gin.git
refactor: refactor make trust ip
This commit is contained in:
parent
162a228e7c
commit
0dd4fe5b48
3
gin.go
3
gin.go
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue