func writeEtcHostsContents(w io.Writer, fqdn string, cidrs []*net.IPNet, extraHosts []string) {
	index := strings.Index(fqdn, ".")
	name := fqdn[:index]
	var hostnames string
	if index == len(fqdn)-1 { // dot comes at the end - no domain
		hostnames = name
	} else {
		if fqdn[len(fqdn)-1] == '.' { // strip a final trailing dot
			fqdn = fqdn[:len(fqdn)-1]
		}
		hostnames = fqdn + " " + name
	}

	fmt.Fprintln(w, "# created by Weave - BEGIN")
	fmt.Fprintln(w, "# container hostname")
	for _, cidr := range cidrs {
		fmt.Fprintf(w, "%-15s %s\n", cidr.IP, hostnames)
	}
	fmt.Fprintln(w)
	fmt.Fprintln(w, "# static names added with --add-host")
	for _, eh := range extraHosts {
		parts := strings.SplitN(eh, ":", 2)
		if len(parts) != 2 {
			continue
		}
		fmt.Fprintf(w, "%-15s %s\n", parts[1], parts[0])
	}
	fmt.Fprintln(w)
	fmt.Fprintln(w, "# default localhost entries")
	fmt.Fprintln(w, "127.0.0.1       localhost")
	fmt.Fprintln(w, "::1             ip6-localhost ip6-loopback")
	fmt.Fprintln(w, "fe00::0         ip6-localnet")
	fmt.Fprintln(w, "ff00::0         ip6-mcastprefix")
	fmt.Fprintln(w, "ff02::1         ip6-allnodes")
	fmt.Fprintln(w, "ff02::2         ip6-allrouters")
	fmt.Fprintln(w, "# created by Weave - END")
}
// we assume (for compatibility with the weave script) that fqdn has a dot
// between hostname and domain. domain may be blank.
we assume (for compatibility with the weave script) that fqdn has a dot
between hostname and domain. domain may be blank.
// we assume ( for compatibility with the weave script ) that fqdn has a dot // between hostname and domain . domain may be blank .
func writeEtcHostsContents(w io.Writer, fqdn string, cidrs []*net.IPNet, extraHosts []string) {
	index := strings.Index(fqdn, ".")
	name := fqdn[:index]
	var hostnames string
	if index == len(fqdn)-1 { 
		hostnames = name
	} else {
		if fqdn[len(fqdn)-1] == '.' { 
			fqdn = fqdn[:len(fqdn)-1]
		}
		hostnames = fqdn + " " + name
	}
	fmt.Fprintln(w, "# created by Weave - BEGIN")
	fmt.Fprintln(w, "# container hostname")
	for _, cidr := range cidrs {
		fmt.Fprintf(w, "%-15s %s\n", cidr.IP, hostnames)
	}
	fmt.Fprintln(w)
	fmt.Fprintln(w, "# static names added with --add-host")
	for _, eh := range extraHosts {
		parts := strings.SplitN(eh, ":", 2)
		if len(parts) != 2 {
			continue
		}
		fmt.Fprintf(w, "%-15s %s\n", parts[1], parts[0])
	}
	fmt.Fprintln(w)
	fmt.Fprintln(w, "# default localhost entries")
	fmt.Fprintln(w, "127.0.0.1       localhost")
	fmt.Fprintln(w, "::1             ip6-localhost ip6-loopback")
	fmt.Fprintln(w, "fe00::0         ip6-localnet")
	fmt.Fprintln(w, "ff00::0         ip6-mcastprefix")
	fmt.Fprintln(w, "ff02::1         ip6-allnodes")
	fmt.Fprintln(w, "ff02::2         ip6-allrouters")
	fmt.Fprintln(w, "# created by Weave - END")
}
func writeEtcHostsContents ( w io . Writer , fqdn string , cidrs [ ] * net . IPNet , extraHosts [ ] string ) { index := strings . Index ( fqdn , " " ) name := fqdn [ : index ] var hostnames string if index == len ( fqdn ) - 1 { hostnames = name } else { if fqdn [ len ( fqdn ) - 1 ] == '.' { fqdn = fqdn [ : len ( fqdn ) - 1 ] } hostnames = fqdn + " " + name } fmt . Fprintln ( w , " " ) fmt . Fprintln ( w , " " ) for _ , cidr := range cidrs { fmt . Fprintf ( w , " \n " , cidr . IP , hostnames ) } fmt . Fprintln ( w ) fmt . Fprintln ( w , " " ) for _ , eh := range extraHosts { parts := strings . SplitN ( eh , " " , 2 ) if len ( parts ) != 2 { continue } fmt . Fprintf ( w , " \n " , parts [ 1 ] , parts [ 0 ] ) } fmt . Fprintln ( w ) fmt . Fprintln ( w , " " ) fmt . Fprintln ( w , " " ) fmt . Fprintln ( w , " " ) fmt . Fprintln ( w , " " ) fmt . Fprintln ( w , " " ) fmt . Fprintln ( w , " " ) fmt . Fprintln ( w , " " ) fmt . Fprintln ( w , " " ) }
we assume (for compatibility with the weave script) that fqdn has a dot
between hostname and domain.
we assume ( for compatibility with the weave script ) that fqdn has a dot between hostname and domain .
// dot comes at the end - no domain // strip a final trailing dot