goodhosts.go
func (h *Hosts) Remove(ip string, hosts ...string) error {
	var outputLines []HostsLine

	if net.ParseIP(ip) == nil {
		return errors.New(fmt.Sprintf("%q is an invalid IP address.", ip))
	}

	for _, line := range h.Lines {

		// Bad lines or comments just get readded.
		if line.Err != nil || line.IsComment() || line.IP != ip {
			outputLines = append(outputLines, line)
			continue
		}

		var newHosts []string
		for _, checkHost := range line.Hosts {
			if !itemInSlice(checkHost, hosts) {
				newHosts = append(newHosts, checkHost)
			}
		}

		// If hosts is empty, skip the line completely.
		if len(newHosts) > 0 {
			newLineRaw := line.IP

			for _, host := range newHosts {
				newLineRaw = fmt.Sprintf("%s %s", newLineRaw, host)
			}
			newLine := NewHostsLine(newLineRaw)
			outputLines = append(outputLines, newLine)
		}
	}

	h.Lines = outputLines
	return nil
}
func (h *Hosts) Remove(ip string, hosts ...string) error {
	var outputLines []HostsLine

	if net.ParseIP(ip) == nil {
		return errors.New(fmt.Sprintf("%q is an invalid IP address.", ip))
	}

	for _, line := range h.Lines {

		// Bad lines or comments just get readded.
		if line.Err != nil || line.IsComment() || line.IP != ip {
			outputLines = append(outputLines, line)
			continue
		}

		var newHosts []string
		for _, checkHost := range line.Hosts {
			if !itemInSlice(checkHost, hosts) {
				newHosts = append(newHosts, checkHost)
			}
		}

		// If hosts is empty, skip the line completely.
		if len(newHosts) > 0 {
			newLineRaw := line.IP

			for _, host := range newHosts {
				newLineRaw = fmt.Sprintf("%s %s", newLineRaw, host)
			}
			newLine := NewHostsLine(newLineRaw)
			outputLines = append(outputLines, newLine)
		}
	}

	h.Lines = outputLines
	return nil
}
func ( h * Hosts ) Remove ( ip string , hosts ... string ) error { var outputLines [ ] HostsLine if net . ParseIP ( ip ) == nil { return errors . New ( fmt . Sprintf ( " " , ip ) ) } for _ , line := range h . Lines { // Bad lines or comments just get readded. if line . Err != nil || line . IsComment ( ) || line . IP != ip { outputLines = append ( outputLines , line ) continue } var newHosts [ ] string for _ , checkHost := range line . Hosts { if ! itemInSlice ( checkHost , hosts ) { newHosts = append ( newHosts , checkHost ) } } // If hosts is empty, skip the line completely. if len ( newHosts ) > 0 { newLineRaw := line . IP for _ , host := range newHosts { newLineRaw = fmt . Sprintf ( " " , newLineRaw , host ) } newLine := NewHostsLine ( newLineRaw ) outputLines = append ( outputLines , newLine ) } } h . Lines = outputLines return nil }
// Remove an entry from the hosts file.
Remove an entry from the hosts file .