hosts

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrHostnameInvalid indicates that the hostname is invalid.
	ErrHostnameInvalid = errors.New("hosts: invalid hostname")

	// ErrHostnameIsIP indicates that the hostname is an IP address.
	ErrHostnameIsIP = errors.New("hosts: hostname is IP address")
)

These errors can be tested against using errors.Is. They are never returned directly.

Functions

This section is empty.

Types

type File

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

File is an in-memory representation of a hosts-file.

func Open

func Open(filename string) (*File, error)

Open opens the hosts-file and returns a representation.

func (File) HasIP

func (h File) HasIP(ip string) bool

HasIP returns true if the ip exists in the hosts file.

func (File) IP

func (h File) IP(hostname string) (string, error)

IP returns the IP address associated with the given hostname, if any.

func (*File) Map

func (h *File) Map(hostname, ip string) error

Map maps the specified hostname to the given IP.

func (File) Records

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

Records returns an array of all entries in the hosts-file.

func (File) Save

func (h File) Save() error

Save saves the changes to the hosts-file.

func (*File) Unmap

func (h *File) Unmap(hostname string) error

Unmap removes the given hostname mapping.

type Record

type Record hostsfile.Record

Record represent a single line from a hosts-file.

Jump to

Keyboard shortcuts

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