Little helper to run CNCF's k3s in Docker
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
k3d/vendor/github.com/goodhosts/hostsfile
iwilltry42 5cd9aa1d08
chore: update deps
5 months ago
..
mage chore: update deps 5 months ago
.gitignore chore: update deps 5 months ago
LICENSE [Feature] add: config options to configure extra hosts (#938) 3 years ago
README.md chore: update deps 5 months ago
build.go chore: update deps 5 months ago
hosts.go chore: update deps 5 months ago
hostsline.go chore: update deps 5 months ago
lookup.go chore: update deps 5 months ago
magefile.go chore: update deps 5 months ago
os.go chore: update deps 5 months ago
os_windows.go chore: update deps 5 months ago
slice.go chore: update deps 5 months ago

README.md

Go package for working with a system's hostsfile

codecov Go Reference

Reads the content of a file in the hosts format into go structs for easy manipulation in go programs. When all changes are complete you can Flush the hosts file back to disk to save your changes. Supports an indexing system on both ips and hosts for quick management of large hosts files.

Simple Usage

Simple usage reading in your system's hosts file and adding an entry for the ip 192.168.1.1 and the host my-hostname

package main

import (
	"log"
	
	"github.com/goodhosts/hostsfile"
)

func main() {
    hosts, err := hostsfile.NewHosts()
    if err != nil {
        log.Fatal(err.Error())
    }
    if err := hosts.Add("192.168.1.1", "my-hostname"); err != nil {
        log.Fatal(err.Error())
    }
    if err := hosts.Flush(); err != nil {
        log.Fatal(err.Error())
    }
}

Other Usage

Read in a hosts file from a custom location which is not the system default, this is useful for tests or systems with non-standard hosts file locations.

hosts, err := hostsfile.NewCustomHosts("./my-custom-hostsfile")

Use Add to put an ip and host combination in the hosts file

err := hosts.Add("192.168.1.1", "my-hostname")

Add is variadic and can take multiple hosts to add for the same ip

err := hosts.Add("192.168.1.1", "my-hostname", "another-hostname")

Use Remove to drop an ip and host combination from the hosts file

err := hosts.Remove("192.168.1.1", "my-hostname")

Remove is variadic and can take multiple hosts to remove from the same ip

err := hosts.Remove("192.168.1.1", "my-hostname", "another-hostname")

Flush the hosts file changes back to disk

err := hosts.Flush()