Merge pull request #3929 from manuelbuil/dual-stack-funcitons_engine

[engine-1.21] Add functions to separate ipv4 from ipv6 functions
pull/3951/head
Manuel Buil 2021-08-27 22:37:30 +02:00 committed by GitHub
commit a4c8810e5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 0 deletions

View File

@ -63,3 +63,25 @@ func GetFirst4String(elems []string) (string, error) {
}
return ip.String(), nil
}
// JoinIP4Nets stringifies and joins a list of IPv4 networks with commas.
func JoinIP4Nets(elems []*net.IPNet) string {
var strs []string
for _, elem := range elems {
if elem != nil && elem.IP.To4() != nil {
strs = append(strs, elem.String())
}
}
return strings.Join(strs, ",")
}
// JoinIP6Nets stringifies and joins a list of IPv6 networks with commas.
func JoinIP6Nets(elems []*net.IPNet) string {
var strs []string
for _, elem := range elems {
if elem != nil && elem.IP.To4() == nil {
strs = append(strs, elem.String())
}
}
return strings.Join(strs, ",")
}