hostsfile

package
v0.0.0-...-e5e9848 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2022 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Location = "/etc/hosts"

OS-specific default hosts-file location.

Functions

func Encode

func Encode(w io.Writer, h Hostsfile) error

Return the text representation of the hosts file.

Types

type Hostsfile

type Hostsfile struct {
	// contains filtered or unexported fields
}

Represents a hosts file. Records match a single line in the file.

func Decode

func Decode(rdr io.Reader) (Hostsfile, error)

Decodes the raw text of a hostsfile into a Hostsfile struct. If a line contains both an IP address and a comment, the comment will be lost.

Interface example from the image package.

func (*Hostsfile) Records

func (h *Hostsfile) Records() []*Record

Records returns an array of all entries in the hostsfile.

func (*Hostsfile) Remove

func (h *Hostsfile) Remove(hostname string) (found bool)

Removes all references to hostname from the file. Returns false if the record was not found in the file.

func (*Hostsfile) Set

func (h *Hostsfile) Set(ipa net.IPAddr, hostname string) error

Adds a record to the list. If the hostname is present with a different IP address, it will be reassigned. If the record is already present with the same hostname/IP address data, it will not be added again.

type Record

type Record struct {
	IpAddress net.IPAddr
	Hostnames map[string]bool
	// contains filtered or unexported fields
}

A single line in the hosts file

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL