Merge pull request #829 from rlguarino/ross/2017-06-08T18-48-35-07-00

feat(template): wrap IPv6 addresses in []
This commit is contained in:
Manuel Alejandro de Brito Fontes 2017-06-09 13:21:30 -04:00 committed by GitHub
commit dbb12afbb9
3 changed files with 35 additions and 1 deletions

View file

@ -145,9 +145,24 @@ var (
"hasSuffix": strings.HasSuffix,
"toUpper": strings.ToUpper,
"toLower": strings.ToLower,
"formatIP": formatIP,
}
)
// fomatIP will wrap IPv6 addresses in [] and return IPv4 addresses
// without modification. If the input cannot be parsed as an IP address
// it is returned without modification.
func formatIP(input string) string {
ip := net.ParseIP(input)
if ip == nil {
return input
}
if v4 := ip.To4(); v4 != nil {
return input
}
return fmt.Sprintf("[%s]", input)
}
// buildResolvers returns the resolvers reading the /etc/resolv.conf file
func buildResolvers(a interface{}) string {
// NGINX need IPV6 addresses to be surrounded by brakets