hostsfile

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2020 License: Apache-2.0 Imports: 7 Imported by: 11

Documentation

Index

Constants

View Source
const HostsFilePath = "/etc/hosts"

Variables

This section is empty.

Functions

This section is empty.

Types

type Hosts

type Hosts struct {
	Path  string
	Lines []HostsLine
}

func NewCustomHosts

func NewCustomHosts(osHostsFilePath string) (Hosts, error)

Return a new instance of “Hosts“ using a custom hosts file path.

func NewHosts

func NewHosts() (Hosts, error)

Return a new instance of “Hosts“ using the default hosts file path.

func (*Hosts) Add

func (h *Hosts) Add(ip string, hosts ...string) error

Add an entry to the hosts file.

func (Hosts) Flush

func (h Hosts) Flush() error

Flush any changes made to hosts file.

func (Hosts) Has

func (h Hosts) Has(ip string, host string) bool

Return a bool if ip/host combo in hosts file.

func (Hosts) HasHostname

func (h Hosts) HasHostname(host string) bool

Return a bool if hostname in hosts file.

func (Hosts) HasIp

func (h Hosts) HasIp(ip string) bool

func (*Hosts) IsWritable

func (h *Hosts) IsWritable() bool

Return ```true``` if hosts file is writable.

func (*Hosts) Load

func (h *Hosts) Load() error

Load the hosts file into ```l.Lines```. ```Load()``` is called by ```NewHosts()``` and ```Hosts.Flush()``` so you generally you won't need to call this yourself.

func (*Hosts) Remove

func (h *Hosts) Remove(ip string, hosts ...string) error

Remove an entry from the hosts file.

func (*Hosts) RemoveByHostname

func (h *Hosts) RemoveByHostname(host string) error

Remove entries by hostname from the hosts file.

func (*Hosts) RemoveByIp

func (h *Hosts) RemoveByIp(ip string) error

type HostsLine

type HostsLine struct {
	IP      string
	Hosts   []string
	Raw     string
	Err     error
	Comment string
}

func NewHostsLine

func NewHostsLine(raw string) HostsLine

Return a new instance of ```HostsLine```.

func (*HostsLine) HasComment added in v0.0.3

func (l *HostsLine) HasComment() bool

func (*HostsLine) IsComment

func (l *HostsLine) IsComment() bool

func (*HostsLine) IsMalformed

func (l *HostsLine) IsMalformed() bool

func (*HostsLine) IsValid

func (l *HostsLine) IsValid() bool

func (*HostsLine) RegenRaw

func (l *HostsLine) RegenRaw()

func (*HostsLine) ToRaw added in v0.0.3

func (l *HostsLine) ToRaw() string

Jump to

Keyboard shortcuts

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