You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: hosts.go
    path of file: ./repos/podman/vendor/github.com/containers/common/libnetwork/etchosts
    
    the code of the file until where you have to start completion: package etchosts

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"os"
	"strings"

	"github.com/containers/common/pkg/config"
	"golang.org/x/exp/slices"
)

const (
	HostContainersInternal = "host.containers.internal"
	HostGateway            = "host-gateway"
	localhost              = "localhost"
	hostDockerInternal     = "host.docker.internal"
)

type HostEntries []HostEntry

type HostEntry str
    
func writeHostFile(file string, userEntries, containerIPs HostEntries) error {
	f, err := os.Create(file)
	if err != nil {
		return err
	}
	defer f.Close()

	names := make(map[string]struct{})
	for _, entry := range userEntries {
		for _, name := range entry.Names {
			names[name] = struct{}{}
		}
		if _, err = f.WriteString(formatLine(entry.IP, entry.Names)); err != nil {
			return err
		}
	}

	return addEntriesIfNotExists(f, containerIPs, names)
}