Last active
February 9, 2020 22:14
-
-
Save qdm12/9f900675aac0f14ea4a4890d79b39833 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package params | |
import ( | |
"fmt" | |
"net" | |
"strings" | |
) | |
// GetExtraSubnets obtains the CIDR subnets from the comma separated list of the | |
// environment variable EXTRA_SUBNETS | |
func (p *paramsReader) GetExtraSubnets() (extraSubnets []net.IPNet, err error) { | |
s, err := p.envParams.GetEnv("EXTRA_SUBNETS") | |
if err != nil { | |
return nil, err | |
} else if s == "" { | |
return nil, nil | |
} | |
subnets := strings.Split(s, ",") | |
for _, subnet := range subnets { | |
_, cidr, err := net.ParseCIDR(subnet) | |
if err != nil { | |
return nil, fmt.Errorf("could not parse subnet %q from environment variable with key EXTRA_SUBNETS: %w", subnet, err) | |
} else if cidr == nil { | |
return nil, fmt.Errorf("parsing subnet %q resulted in a nil CIDR", subnet) | |
} | |
extraSubnets = append(extraSubnets, *cidr) | |
} | |
return extraSubnets, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment